Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / System.Runtime.DurableInstancing / System / Runtime / ReadOnlyDictionary.cs / 1305376 / ReadOnlyDictionary.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Runtime { using System.Collections; using System.Collections.Generic; [Serializable] class ReadOnlyDictionary: IDictionary { IDictionary dictionary; public ReadOnlyDictionary(IDictionary dictionary) : this(dictionary, true) { } public ReadOnlyDictionary(IDictionary dictionary, bool makeCopy) { if (makeCopy) { this.dictionary = new Dictionary (dictionary); } else { this.dictionary = dictionary; } } public int Count { get { return this.dictionary.Count; } } public bool IsReadOnly { get { return true; } } public ICollection Keys { get { return this.dictionary.Keys; } } public ICollection Values { get { return this.dictionary.Values; } } public TValue this[TKey key] { get { return this.dictionary[key]; } set { throw Fx.Exception.AsError(CreateReadOnlyException()); } } public static IDictionary Create(IDictionary dictionary) { if (dictionary.IsReadOnly) { return dictionary; } else { return new ReadOnlyDictionary (dictionary); } } Exception CreateReadOnlyException() { return new InvalidOperationException(SRCore.DictionaryIsReadOnly); } public void Add(TKey key, TValue value) { throw Fx.Exception.AsError(CreateReadOnlyException()); } public void Add(KeyValuePair item) { throw Fx.Exception.AsError(CreateReadOnlyException()); } public void Clear() { throw Fx.Exception.AsError(CreateReadOnlyException()); } public bool Contains(KeyValuePair item) { return this.dictionary.Contains(item); } public bool ContainsKey(TKey key) { return this.dictionary.ContainsKey(key); } public void CopyTo(KeyValuePair [] array, int arrayIndex) { this.dictionary.CopyTo(array, arrayIndex); } public IEnumerator > GetEnumerator() { return this.dictionary.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } public bool Remove(TKey key) { throw Fx.Exception.AsError(CreateReadOnlyException()); } public bool Remove(KeyValuePair item) { throw Fx.Exception.AsError(CreateReadOnlyException()); } public bool TryGetValue(TKey key, out TValue value) { return this.dictionary.TryGetValue(key, out value); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Runtime { using System.Collections; using System.Collections.Generic; [Serializable] class ReadOnlyDictionary : IDictionary { IDictionary dictionary; public ReadOnlyDictionary(IDictionary dictionary) : this(dictionary, true) { } public ReadOnlyDictionary(IDictionary dictionary, bool makeCopy) { if (makeCopy) { this.dictionary = new Dictionary (dictionary); } else { this.dictionary = dictionary; } } public int Count { get { return this.dictionary.Count; } } public bool IsReadOnly { get { return true; } } public ICollection Keys { get { return this.dictionary.Keys; } } public ICollection Values { get { return this.dictionary.Values; } } public TValue this[TKey key] { get { return this.dictionary[key]; } set { throw Fx.Exception.AsError(CreateReadOnlyException()); } } public static IDictionary Create(IDictionary dictionary) { if (dictionary.IsReadOnly) { return dictionary; } else { return new ReadOnlyDictionary (dictionary); } } Exception CreateReadOnlyException() { return new InvalidOperationException(SRCore.DictionaryIsReadOnly); } public void Add(TKey key, TValue value) { throw Fx.Exception.AsError(CreateReadOnlyException()); } public void Add(KeyValuePair item) { throw Fx.Exception.AsError(CreateReadOnlyException()); } public void Clear() { throw Fx.Exception.AsError(CreateReadOnlyException()); } public bool Contains(KeyValuePair item) { return this.dictionary.Contains(item); } public bool ContainsKey(TKey key) { return this.dictionary.ContainsKey(key); } public void CopyTo(KeyValuePair [] array, int arrayIndex) { this.dictionary.CopyTo(array, arrayIndex); } public IEnumerator > GetEnumerator() { return this.dictionary.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } public bool Remove(TKey key) { throw Fx.Exception.AsError(CreateReadOnlyException()); } public bool Remove(KeyValuePair item) { throw Fx.Exception.AsError(CreateReadOnlyException()); } public bool TryGetValue(TKey key, out TValue value) { return this.dictionary.TryGetValue(key, out value); } } } // 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
- StoreContentChangedEventArgs.cs
- ItemMap.cs
- JsonServiceDocumentSerializer.cs
- RuleSetDialog.Designer.cs
- RecognizedAudio.cs
- CodeCommentStatement.cs
- RecognizedPhrase.cs
- WindowsContainer.cs
- DataObject.cs
- CFStream.cs
- SQLBytesStorage.cs
- StreamingContext.cs
- DisplayNameAttribute.cs
- WebPartConnectionsCloseVerb.cs
- PersistenceException.cs
- InvalidFilterCriteriaException.cs
- DataServiceEntityAttribute.cs
- MimeFormImporter.cs
- JpegBitmapDecoder.cs
- SoapTypeAttribute.cs
- Pair.cs
- XmlQueryContext.cs
- SafeEventLogWriteHandle.cs
- AlignmentYValidation.cs
- DescendantQuery.cs
- CreateUserWizardDesigner.cs
- CodeAssignStatement.cs
- HttpContext.cs
- SystemInfo.cs
- Int32KeyFrameCollection.cs
- DataGridViewCell.cs
- CategoryState.cs
- SystemIPInterfaceStatistics.cs
- COM2EnumConverter.cs
- ListItem.cs
- CompositionCommandSet.cs
- MatcherBuilder.cs
- ColumnHeaderConverter.cs
- AttributeData.cs
- exports.cs
- ResourceDisplayNameAttribute.cs
- DataSpaceManager.cs
- Serialization.cs
- SamlAuthorityBinding.cs
- Comparer.cs
- ErrorInfoXmlDocument.cs
- ExpressionBinding.cs
- SqlConnectionPoolGroupProviderInfo.cs
- TransformerConfigurationWizardBase.cs
- PixelFormatConverter.cs
- ReversePositionQuery.cs
- ConditionCollection.cs
- WorkflowItemPresenter.cs
- DataGridViewImageCell.cs
- HyperLinkStyle.cs
- SelectionRange.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- ArcSegment.cs
- SaveFileDialog.cs
- XmlDataSourceNodeDescriptor.cs
- JsonFormatGeneratorStatics.cs
- MimeTypePropertyAttribute.cs
- AutomationPatternInfo.cs
- NameValueSectionHandler.cs
- AdornerHitTestResult.cs
- ToolBarTray.cs
- DataGridViewButtonCell.cs
- SplitContainer.cs
- TemplateControl.cs
- StorageEntityTypeMapping.cs
- X509Certificate2.cs
- TextElement.cs
- documentsequencetextcontainer.cs
- StrokeDescriptor.cs
- DataReaderContainer.cs
- SoapCommonClasses.cs
- CodeGeneratorOptions.cs
- ServerTooBusyException.cs
- RootBrowserWindowProxy.cs
- SqlCacheDependency.cs
- ApplicationSettingsBase.cs
- XPathCompileException.cs
- XmlWrappingReader.cs
- ReachVisualSerializer.cs
- COM2EnumConverter.cs
- ClientScriptItem.cs
- AuthStoreRoleProvider.cs
- Dispatcher.cs
- XmlComment.cs
- ParallelRangeManager.cs
- _ScatterGatherBuffers.cs
- QueryHandler.cs
- NativeMethodsCLR.cs
- SerializationSectionGroup.cs
- WindowsToolbarItemAsMenuItem.cs
- WindowsScrollBar.cs
- QueryOperationResponseOfT.cs
- SoapIncludeAttribute.cs
- ValueTypeFixupInfo.cs
- StreamSecurityUpgradeInitiatorBase.cs