Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Collections / EmptyReadOnlyDictionaryInternal.cs / 1305376 / EmptyReadOnlyDictionaryInternal.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: EmptyReadOnlyDictionaryInternal ** **[....] ** ** ** Purpose: List for exceptions. ** ** ===========================================================*/ using System.Diagnostics.Contracts; namespace System.Collections { /// This is a simple implementation of IDictionary that is empty and readonly. [Serializable] internal sealed class EmptyReadOnlyDictionaryInternal: IDictionary { // Note that this class must be agile with respect to AppDomains. See its usage in // System.Exception to understand why this is the case. public EmptyReadOnlyDictionaryInternal() { } // IEnumerable members IEnumerator IEnumerable.GetEnumerator() { return new NodeEnumerator(); } // ICollection members public void CopyTo(Array array, int index) { if (array==null) throw new ArgumentNullException("array"); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (index < 0) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if ( array.Length - index < this.Count ) throw new ArgumentException( Environment.GetResourceString("ArgumentOutOfRange_Index"), "index"); Contract.EndContractBlock(); // the actual copy is a NOP } public int Count { get { return 0; } } public Object SyncRoot { get { return this; } } public bool IsSynchronized { get { return false; } } // IDictionary members public Object this[Object key] { get { if (key == null) { throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); return null; } set { if (key == null) { throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); } 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"); Contract.EndContractBlock(); throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); } } public ICollection Keys { get { return new Object[0]; } } public ICollection Values { get { return new Object[0]; } } public bool Contains(Object key) { return false; } public void Add(Object key, Object value) { if (key == null) { throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); } 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"); Contract.EndContractBlock(); throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); } public void Clear() { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); } public bool IsReadOnly { get { return true; } } public bool IsFixedSize { get { return true; } } public IDictionaryEnumerator GetEnumerator() { return new NodeEnumerator(); } public void Remove(Object key) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); } private sealed class NodeEnumerator : IDictionaryEnumerator { public NodeEnumerator() { } // IEnumerator members public bool MoveNext() { return false; } public Object Current { get { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumOpCantHappen")); } } public void Reset() { } // IDictionaryEnumerator members public Object Key { get { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumOpCantHappen")); } } public Object Value { get { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumOpCantHappen")); } } public DictionaryEntry Entry { get { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumOpCantHappen")); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: EmptyReadOnlyDictionaryInternal ** **[....] ** ** ** Purpose: List for exceptions. ** ** ===========================================================*/ using System.Diagnostics.Contracts; namespace System.Collections { /// This is a simple implementation of IDictionary that is empty and readonly. [Serializable] internal sealed class EmptyReadOnlyDictionaryInternal: IDictionary { // Note that this class must be agile with respect to AppDomains. See its usage in // System.Exception to understand why this is the case. public EmptyReadOnlyDictionaryInternal() { } // IEnumerable members IEnumerator IEnumerable.GetEnumerator() { return new NodeEnumerator(); } // ICollection members public void CopyTo(Array array, int index) { if (array==null) throw new ArgumentNullException("array"); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (index < 0) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if ( array.Length - index < this.Count ) throw new ArgumentException( Environment.GetResourceString("ArgumentOutOfRange_Index"), "index"); Contract.EndContractBlock(); // the actual copy is a NOP } public int Count { get { return 0; } } public Object SyncRoot { get { return this; } } public bool IsSynchronized { get { return false; } } // IDictionary members public Object this[Object key] { get { if (key == null) { throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); return null; } set { if (key == null) { throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); } 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"); Contract.EndContractBlock(); throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); } } public ICollection Keys { get { return new Object[0]; } } public ICollection Values { get { return new Object[0]; } } public bool Contains(Object key) { return false; } public void Add(Object key, Object value) { if (key == null) { throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); } 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"); Contract.EndContractBlock(); throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); } public void Clear() { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); } public bool IsReadOnly { get { return true; } } public bool IsFixedSize { get { return true; } } public IDictionaryEnumerator GetEnumerator() { return new NodeEnumerator(); } public void Remove(Object key) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); } private sealed class NodeEnumerator : IDictionaryEnumerator { public NodeEnumerator() { } // IEnumerator members public bool MoveNext() { return false; } public Object Current { get { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumOpCantHappen")); } } public void Reset() { } // IDictionaryEnumerator members public Object Key { get { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumOpCantHappen")); } } public Object Value { get { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumOpCantHappen")); } } public DictionaryEntry Entry { get { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumOpCantHappen")); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- MeasureData.cs
- ITextView.cs
- CompositeScriptReference.cs
- InstanceStoreQueryResult.cs
- SpotLight.cs
- WebControlsSection.cs
- GeometryHitTestParameters.cs
- SqlHelper.cs
- ComboBox.cs
- WebPartDisplayModeCancelEventArgs.cs
- Canonicalizers.cs
- FormsAuthentication.cs
- SystemPens.cs
- StorageMappingFragment.cs
- BinaryWriter.cs
- CategoryGridEntry.cs
- PropertyChangedEventManager.cs
- DurableOperationContext.cs
- PlanCompiler.cs
- Page.cs
- Ref.cs
- Compiler.cs
- DataObjectEventArgs.cs
- InternalCache.cs
- dbenumerator.cs
- HtmlInputCheckBox.cs
- BindingMAnagerBase.cs
- CacheChildrenQuery.cs
- XmlnsCompatibleWithAttribute.cs
- WinFormsSpinner.cs
- IndexedString.cs
- DataChangedEventManager.cs
- XmlLangPropertyAttribute.cs
- DataServiceClientException.cs
- OdbcReferenceCollection.cs
- RegexCapture.cs
- TypeDelegator.cs
- ObjectTag.cs
- XmlSchemaImport.cs
- ProcessModule.cs
- DataTemplateSelector.cs
- WrappingXamlSchemaContext.cs
- DesignTable.cs
- RtfControls.cs
- StateMachineWorkflow.cs
- UnaryNode.cs
- GroupDescription.cs
- ConfigXmlElement.cs
- UITypeEditor.cs
- GenericQueueSurrogate.cs
- DynamicRenderer.cs
- DataTableExtensions.cs
- ShaderRenderModeValidation.cs
- TraceUtility.cs
- StorageEntityContainerMapping.cs
- BoolExpr.cs
- ColumnHeader.cs
- ResourceSet.cs
- UrlMappingsModule.cs
- ModelVisual3D.cs
- CodeTypeMemberCollection.cs
- HyperLinkColumn.cs
- SuppressIldasmAttribute.cs
- LexicalChunk.cs
- CellRelation.cs
- TypeConstant.cs
- ValidatorCollection.cs
- RichTextBoxAutomationPeer.cs
- DesignerResources.cs
- ThemeDirectoryCompiler.cs
- TraceLog.cs
- XmlUTF8TextReader.cs
- CodeSnippetExpression.cs
- GridViewAutomationPeer.cs
- FixedSOMFixedBlock.cs
- PrivilegeNotHeldException.cs
- ActivatedMessageQueue.cs
- WindowsListViewScroll.cs
- PageParserFilter.cs
- ImageProxy.cs
- PassportAuthentication.cs
- ViewGenerator.cs
- Geometry.cs
- PasswordRecoveryDesigner.cs
- XmlSerializer.cs
- Normalization.cs
- EventItfInfo.cs
- DesignerExtenders.cs
- InfoCardUIAgent.cs
- BamlBinaryWriter.cs
- DesignerAttribute.cs
- CaseCqlBlock.cs
- EntityContainerAssociationSet.cs
- KerberosSecurityTokenAuthenticator.cs
- DPTypeDescriptorContext.cs
- TextEditorParagraphs.cs
- CacheVirtualItemsEvent.cs
- IPipelineRuntime.cs
- Byte.cs
- DrawToolTipEventArgs.cs