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
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ByteAnimationBase.cs
- columnmapkeybuilder.cs
- String.cs
- PageSetupDialog.cs
- DelegateBodyWriter.cs
- StringSorter.cs
- GridViewEditEventArgs.cs
- CodeMemberMethod.cs
- ClientRolePrincipal.cs
- SocketElement.cs
- XmlHelper.cs
- Vector3D.cs
- RelatedView.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- assemblycache.cs
- HttpCacheVary.cs
- HtmlEncodedRawTextWriter.cs
- JoinSymbol.cs
- RectAnimation.cs
- Rotation3DKeyFrameCollection.cs
- TemplatedWizardStep.cs
- TextBoxBase.cs
- BasicHttpBinding.cs
- CallTemplateAction.cs
- TypeInitializationException.cs
- SerializationStore.cs
- ContainsSearchOperator.cs
- Tracer.cs
- SoapExtensionImporter.cs
- PeerOutputChannel.cs
- SqlDataSourceCommandEventArgs.cs
- Rijndael.cs
- RemoteCryptoRsaServiceProvider.cs
- DesignerTextBoxAdapter.cs
- DataColumnChangeEvent.cs
- DateTimeOffsetConverter.cs
- CodeMemberEvent.cs
- LocalizableAttribute.cs
- XmlCountingReader.cs
- ToolStripItemDataObject.cs
- SQLChars.cs
- HttpApplicationFactory.cs
- AnimationStorage.cs
- PointHitTestParameters.cs
- IsolationInterop.cs
- UrlUtility.cs
- ButtonField.cs
- CacheRequest.cs
- GeneralTransform3DTo2D.cs
- MailBnfHelper.cs
- SafeArrayRankMismatchException.cs
- RelationshipWrapper.cs
- RadioButton.cs
- GlyphElement.cs
- StylusLogic.cs
- DefaultBindingPropertyAttribute.cs
- LambdaCompiler.Lambda.cs
- DecimalMinMaxAggregationOperator.cs
- CaseCqlBlock.cs
- SchemaElementLookUpTable.cs
- ListViewInsertEventArgs.cs
- ResourcePermissionBaseEntry.cs
- SimpleBitVector32.cs
- RMEnrollmentPage2.cs
- Point4D.cs
- ApplicationContext.cs
- DrawingContext.cs
- SecurityPermission.cs
- XmlParserContext.cs
- ReliableMessagingHelpers.cs
- SortDescription.cs
- Int16Animation.cs
- ControlCachePolicy.cs
- HttpListenerElement.cs
- X509Certificate.cs
- WebPartConnectionCollection.cs
- ItemChangedEventArgs.cs
- DrawingImage.cs
- StrokeIntersection.cs
- GridViewEditEventArgs.cs
- FieldDescriptor.cs
- SafeThreadHandle.cs
- ScriptingAuthenticationServiceSection.cs
- FontUnit.cs
- FieldNameLookup.cs
- StylusEventArgs.cs
- SoapSchemaExporter.cs
- SessionViewState.cs
- DetailsViewDeleteEventArgs.cs
- HitTestParameters3D.cs
- DataControlFieldCell.cs
- TextEvent.cs
- SpellerInterop.cs
- AssociationTypeEmitter.cs
- OdbcReferenceCollection.cs
- ExportException.cs
- RelationshipEndCollection.cs
- SecurityStandardsManager.cs
- MessageQueuePermissionEntryCollection.cs
- FixedNode.cs