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
- MimeBasePart.cs
- CheckoutException.cs
- KeyBinding.cs
- MultipleViewPattern.cs
- PagePropertiesChangingEventArgs.cs
- ApplicationServiceManager.cs
- ConnectionConsumerAttribute.cs
- Bidi.cs
- DecoderFallbackWithFailureFlag.cs
- StylusButton.cs
- smtppermission.cs
- Configuration.cs
- BaseComponentEditor.cs
- NumberFunctions.cs
- TaiwanLunisolarCalendar.cs
- HMACSHA1.cs
- NamespaceList.cs
- recordstatefactory.cs
- MailAddressCollection.cs
- SRDisplayNameAttribute.cs
- ScalarOps.cs
- CancelEventArgs.cs
- GcSettings.cs
- complextypematerializer.cs
- EmptyStringExpandableObjectConverter.cs
- CompositeScriptReference.cs
- _SafeNetHandles.cs
- DataTablePropertyDescriptor.cs
- SizeChangedInfo.cs
- Trigger.cs
- DocumentViewerAutomationPeer.cs
- TextParagraphCache.cs
- ObjectSpanRewriter.cs
- IsolatedStorageException.cs
- FileLogRecordStream.cs
- DbFunctionCommandTree.cs
- NavigationFailedEventArgs.cs
- SqlWriter.cs
- XPathDocumentIterator.cs
- StackBuilderSink.cs
- AssemblyResourceLoader.cs
- BooleanAnimationUsingKeyFrames.cs
- PenThreadPool.cs
- Button.cs
- SettingsBindableAttribute.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- DataAdapter.cs
- ErasingStroke.cs
- PauseStoryboard.cs
- ThicknessAnimationBase.cs
- URLString.cs
- SystemIcons.cs
- NavigationProperty.cs
- Win32.cs
- HttpCacheVaryByContentEncodings.cs
- CryptoApi.cs
- NativeMethods.cs
- Graphics.cs
- SiteMapDataSource.cs
- ServiceDocument.cs
- CreateRefExpr.cs
- _PooledStream.cs
- DispatcherTimer.cs
- TextParaLineResult.cs
- ObservableCollectionDefaultValueFactory.cs
- CssStyleCollection.cs
- RegexBoyerMoore.cs
- XmlArrayItemAttribute.cs
- RSAOAEPKeyExchangeDeformatter.cs
- UrlEncodedParameterWriter.cs
- DataControlCommands.cs
- CalendarTable.cs
- validationstate.cs
- ITextView.cs
- ActivityExecutorOperation.cs
- SpStreamWrapper.cs
- ButtonDesigner.cs
- MulticastNotSupportedException.cs
- FileDetails.cs
- BroadcastEventHelper.cs
- ParameterToken.cs
- HttpListener.cs
- PartManifestEntry.cs
- input.cs
- RegisteredArrayDeclaration.cs
- ProfilePropertySettings.cs
- WSSecurityJan2004.cs
- DataSourceCache.cs
- SynchronizationLockException.cs
- CursorConverter.cs
- SlipBehavior.cs
- SplayTreeNode.cs
- BitmapCodecInfo.cs
- ToolStripGripRenderEventArgs.cs
- DragEvent.cs
- TimerElapsedEvenArgs.cs
- ItemCheckEvent.cs
- EntityDataSourceDesigner.cs
- HtmlTableRowCollection.cs
- FileController.cs