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
- XmlWriter.cs
- ILGen.cs
- MessageQueueTransaction.cs
- AttachedAnnotation.cs
- ServiceOperationUIEditor.cs
- DbParameterCollectionHelper.cs
- IPHostEntry.cs
- InvalidDataException.cs
- WebPartUtil.cs
- CompiledXpathExpr.cs
- EntityException.cs
- TreeViewImageIndexConverter.cs
- Composition.cs
- ArglessEventHandlerProxy.cs
- ReadWriteSpinLock.cs
- TextTreeUndoUnit.cs
- StylusPointPropertyUnit.cs
- InstancePersistenceContext.cs
- ProfilePropertySettings.cs
- TextEditorTyping.cs
- WebServiceData.cs
- UrlPath.cs
- XmlChildNodes.cs
- TagMapCollection.cs
- SecurityVerifiedMessage.cs
- HtmlLink.cs
- DecoratedNameAttribute.cs
- WmiEventSink.cs
- Property.cs
- Stream.cs
- InstanceData.cs
- ListSortDescription.cs
- HtmlElementErrorEventArgs.cs
- StateDesigner.LayoutSelectionGlyph.cs
- DetailsViewAutoFormat.cs
- GridViewRowPresenter.cs
- SimpleRecyclingCache.cs
- TreeView.cs
- SqlDataSourceFilteringEventArgs.cs
- RuntimeWrappedException.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- MethodBuilder.cs
- TableLayoutStyleCollection.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- tibetanshape.cs
- ObjectViewEntityCollectionData.cs
- SystemWebSectionGroup.cs
- WindowsEditBox.cs
- MultilineStringEditor.cs
- BigInt.cs
- SimplePropertyEntry.cs
- ReferencedAssembly.cs
- DataGridViewLinkColumn.cs
- Page.cs
- DataColumn.cs
- XmlSerializerFactory.cs
- DecimalAnimation.cs
- COM2AboutBoxPropertyDescriptor.cs
- AuthenticateEventArgs.cs
- DiscoveryDefaults.cs
- WsdlImporterElement.cs
- RolePrincipal.cs
- InternalSafeNativeMethods.cs
- SecurityPermission.cs
- ADMembershipUser.cs
- HtmlFormParameterWriter.cs
- WebBrowserNavigatingEventHandler.cs
- Decoder.cs
- ClickablePoint.cs
- SqlCachedBuffer.cs
- DataGridSortCommandEventArgs.cs
- FixedSOMTableCell.cs
- CodeNamespaceImportCollection.cs
- XmlLanguageConverter.cs
- ParallelRangeManager.cs
- DataGridCommandEventArgs.cs
- XmlSchemaIdentityConstraint.cs
- Interlocked.cs
- DocComment.cs
- FormsAuthenticationCredentials.cs
- RegionInfo.cs
- OpCodes.cs
- EventLogPermissionEntry.cs
- DbMetaDataCollectionNames.cs
- StringReader.cs
- Padding.cs
- HttpCapabilitiesBase.cs
- RegistryKey.cs
- AvTraceFormat.cs
- ToolStripStatusLabel.cs
- PageCatalogPart.cs
- WebPartManagerInternals.cs
- SQLInt32.cs
- TextRenderer.cs
- StoreContentChangedEventArgs.cs
- InputGestureCollection.cs
- TypeSystemHelpers.cs
- PropertyMapper.cs
- ReflectionUtil.cs
- MetabaseSettingsIis7.cs