Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Collections / ListDictionaryInternal.cs / 1305376 / ListDictionaryInternal.cs
using System.Diagnostics.Contracts; // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: ListDictionaryInternal ** **[....] ** ** ** Purpose: List for exceptions. ** ** ===========================================================*/ namespace System.Collections { /// This is a simple implementation of IDictionary using a singly linked list. This /// will be smaller and faster than a Hashtable if the number of elements is 10 or less. /// This should not be used if performance is important for large numbers of elements. [Serializable] internal class ListDictionaryInternal: IDictionary { DictionaryNode head; int version; int count; [NonSerialized] private Object _syncRoot; public ListDictionaryInternal() { } public Object this[Object key] { get { if (key == null) { throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); DictionaryNode node = head; while (node != null) { if ( node.key.Equals(key) ) { return node.value; } node = node.next; } return null; } set { if (key == null) { throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); #if FEATURE_SERIALIZATION if (!key.GetType().IsSerializable) throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), "key"); if( (value != null) && (!value.GetType().IsSerializable ) ) throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), "value"); #endif version++; DictionaryNode last = null; DictionaryNode node; for (node = head; node != null; node = node.next) { if( node.key.Equals(key) ) { break; } last = node; } if (node != null) { // Found it node.value = value; return; } // Not found, so add a new one DictionaryNode newNode = new DictionaryNode(); newNode.key = key; newNode.value = value; if (last != null) { last.next = newNode; } else { head = newNode; } count++; } } public int Count { get { return count; } } public ICollection Keys { get { return new NodeKeyValueCollection(this, true); } } public bool IsReadOnly { get { return false; } } public bool IsFixedSize { get { return false; } } public bool IsSynchronized { get { return false; } } public Object SyncRoot { get { if( _syncRoot == null) { System.Threading.Interlocked.CompareExchange
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- NGCSerializationManagerAsync.cs
- SiteMapDataSource.cs
- TimersDescriptionAttribute.cs
- MethodImplAttribute.cs
- Perspective.cs
- ValueType.cs
- FilterQueryOptionExpression.cs
- DataObjectFieldAttribute.cs
- StyleSelector.cs
- VectorAnimation.cs
- Matrix3D.cs
- AggregatePushdown.cs
- MD5CryptoServiceProvider.cs
- FaultHandlingFilter.cs
- DbMetaDataFactory.cs
- RegistrationServices.cs
- ConnectionManagementSection.cs
- WebPartPersonalization.cs
- SmtpTransport.cs
- NumberFunctions.cs
- SQLGuid.cs
- ZeroOpNode.cs
- CompilationLock.cs
- IgnorePropertiesAttribute.cs
- Authorization.cs
- HostExecutionContextManager.cs
- DrawingImage.cs
- HwndStylusInputProvider.cs
- GatewayIPAddressInformationCollection.cs
- XmlQueryRuntime.cs
- LayoutEditorPart.cs
- ScalarOps.cs
- XmlTextReaderImplHelpers.cs
- SingleAnimationUsingKeyFrames.cs
- WindowsTokenRoleProvider.cs
- EventLogEntry.cs
- Stroke2.cs
- InkSerializer.cs
- SemanticBasicElement.cs
- BinaryMessageFormatter.cs
- WindowsTitleBar.cs
- SpecularMaterial.cs
- Metafile.cs
- ReadOnlyCollectionBase.cs
- AddingNewEventArgs.cs
- RegexRunner.cs
- Misc.cs
- SqlInternalConnectionTds.cs
- BamlLocalizationDictionary.cs
- DataGridPagerStyle.cs
- LeaseManager.cs
- ProfessionalColors.cs
- querybuilder.cs
- FontUnit.cs
- ServiceProviders.cs
- ParameterCollection.cs
- ProxyGenerationError.cs
- EventLogReader.cs
- Point3DAnimationUsingKeyFrames.cs
- CultureInfo.cs
- ListViewTableRow.cs
- Vector3DAnimationUsingKeyFrames.cs
- TextBox.cs
- ArgumentException.cs
- DataGridPagerStyle.cs
- X509Certificate.cs
- SessionEndingCancelEventArgs.cs
- ConsumerConnectionPointCollection.cs
- CreateDataSourceDialog.cs
- ForceCopyBuildProvider.cs
- CodeEntryPointMethod.cs
- PkcsUtils.cs
- ManipulationCompletedEventArgs.cs
- TableHeaderCell.cs
- FlowLayoutPanel.cs
- SchemaElementDecl.cs
- ResourceDescriptionAttribute.cs
- WebBrowserNavigatingEventHandler.cs
- SmtpFailedRecipientsException.cs
- cookiecollection.cs
- AssemblyBuilderData.cs
- OleDbPermission.cs
- ImportDesigner.xaml.cs
- SqlBuilder.cs
- CopyOnWriteList.cs
- BuilderPropertyEntry.cs
- Brushes.cs
- FileAuthorizationModule.cs
- messageonlyhwndwrapper.cs
- Drawing.cs
- WriteFileContext.cs
- FontUnitConverter.cs
- _SslState.cs
- EpmContentDeSerializerBase.cs
- TraceSwitch.cs
- ProfileProvider.cs
- DataGridAddNewRow.cs
- SharedConnectionListener.cs
- FontStyles.cs
- TextTreeTextBlock.cs