Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Speech / Src / Internal / ReadOnlyDictionary.cs / 1 / ReadOnlyDictionary.cs
//------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; namespace System.Speech.Internal { internal class ReadOnlyDictionary: IDictionary { public int Count { get { return _dictionary.Count; } } public IEnumerator > GetEnumerator () { return _dictionary.GetEnumerator (); } public V this [K key] { get { return _dictionary [key]; } set { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } } // Other methods are a pass through to the underlying collection: public bool IsReadOnly { get { return true; } } public bool Contains (KeyValuePair key) { return _dictionary.ContainsKey (key.Key); } public bool ContainsKey (K key) { return _dictionary.ContainsKey (key); } public void CopyTo (KeyValuePair [] array, int index) { ((ICollection >) _dictionary).CopyTo (array, index); } public ICollection Keys { // According to the source of IDictionary.Keys this is a read-only collection. get { return _dictionary.Keys; } } public ICollection Values { // According to the source of IDictionary.Keys this is a read-write collection, // but is a copy of the main dictionary so there's no way to change anything in the main collection. get { return _dictionary.Values; } } // Read-only collection so throw on these methods: public void Add (KeyValuePair key) { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } public void Add (K key, V value) { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } public void Clear () { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } public bool Remove (KeyValuePair key) { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } public bool Remove (K key) { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } IEnumerator IEnumerable.GetEnumerator () { return ((IEnumerable >) this).GetEnumerator (); } bool IDictionary .TryGetValue (K key, out V value) { return InternalDictionary.TryGetValue (key, out value); } // Allow internal code to manipulate internal collection internal Dictionary InternalDictionary { get { return _dictionary; } //set { _dictionary = value; } } private Dictionary _dictionary = new Dictionary (); } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; namespace System.Speech.Internal { internal class ReadOnlyDictionary: IDictionary { public int Count { get { return _dictionary.Count; } } public IEnumerator > GetEnumerator () { return _dictionary.GetEnumerator (); } public V this [K key] { get { return _dictionary [key]; } set { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } } // Other methods are a pass through to the underlying collection: public bool IsReadOnly { get { return true; } } public bool Contains (KeyValuePair key) { return _dictionary.ContainsKey (key.Key); } public bool ContainsKey (K key) { return _dictionary.ContainsKey (key); } public void CopyTo (KeyValuePair [] array, int index) { ((ICollection >) _dictionary).CopyTo (array, index); } public ICollection Keys { // According to the source of IDictionary.Keys this is a read-only collection. get { return _dictionary.Keys; } } public ICollection Values { // According to the source of IDictionary.Keys this is a read-write collection, // but is a copy of the main dictionary so there's no way to change anything in the main collection. get { return _dictionary.Values; } } // Read-only collection so throw on these methods: public void Add (KeyValuePair key) { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } public void Add (K key, V value) { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } public void Clear () { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } public bool Remove (KeyValuePair key) { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } public bool Remove (K key) { throw new NotSupportedException (SR.Get (SRID.CollectionReadOnly)); } IEnumerator IEnumerable.GetEnumerator () { return ((IEnumerable >) this).GetEnumerator (); } bool IDictionary .TryGetValue (K key, out V value) { return InternalDictionary.TryGetValue (key, out value); } // Allow internal code to manipulate internal collection internal Dictionary InternalDictionary { get { return _dictionary; } //set { _dictionary = value; } } private Dictionary _dictionary = new Dictionary (); } } // 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
- MatrixKeyFrameCollection.cs
- Helpers.cs
- DataSet.cs
- MultiView.cs
- ImmutableObjectAttribute.cs
- XamlToRtfWriter.cs
- AnonymousIdentificationModule.cs
- MultipleViewProviderWrapper.cs
- WorkItem.cs
- ClientSettingsStore.cs
- AmbientProperties.cs
- FrameAutomationPeer.cs
- LocationUpdates.cs
- DateTimeOffsetStorage.cs
- HtmlHistory.cs
- ValidatingReaderNodeData.cs
- RuleSetBrowserDialog.cs
- TextRunCacheImp.cs
- CustomErrorCollection.cs
- LinearGradientBrush.cs
- GroupByExpressionRewriter.cs
- MimeParameterWriter.cs
- FormatException.cs
- uribuilder.cs
- KeyedCollection.cs
- Win32.cs
- Semaphore.cs
- CodeIndexerExpression.cs
- ReachBasicContext.cs
- MatchingStyle.cs
- ScrollItemProviderWrapper.cs
- GraphicsState.cs
- MeshGeometry3D.cs
- SecurityException.cs
- FollowerQueueCreator.cs
- StrokeRenderer.cs
- BamlLocalizabilityResolver.cs
- Pointer.cs
- BitmapMetadata.cs
- ReflectionTypeLoadException.cs
- Timer.cs
- SerialErrors.cs
- CodeIndexerExpression.cs
- AutomationPeer.cs
- DesignTimeTemplateParser.cs
- WeakReadOnlyCollection.cs
- IPGlobalProperties.cs
- TabRenderer.cs
- EntityDataSourceDesignerHelper.cs
- CodeNamespaceImport.cs
- HtmlControlAdapter.cs
- PersonalizablePropertyEntry.cs
- DataServiceRequestOfT.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- DataShape.cs
- SequenceDesignerAccessibleObject.cs
- ActiveXSite.cs
- Transform3DGroup.cs
- FormViewDeleteEventArgs.cs
- PropertyKey.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- HashSetEqualityComparer.cs
- PrinterSettings.cs
- LinqMaximalSubtreeNominator.cs
- QueryOpeningEnumerator.cs
- FixedSOMContainer.cs
- TreeWalkHelper.cs
- DateTimeHelper.cs
- AffineTransform3D.cs
- IntegerValidatorAttribute.cs
- ProcessThreadDesigner.cs
- Matrix3DStack.cs
- BatchParser.cs
- DiscoveryServerProtocol.cs
- WindowPatternIdentifiers.cs
- ScrollData.cs
- GenericTextProperties.cs
- OrderToken.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- KnownTypes.cs
- DoubleAnimationUsingKeyFrames.cs
- RedistVersionInfo.cs
- TextClipboardData.cs
- URLString.cs
- AnnotationStore.cs
- HttpEncoder.cs
- Currency.cs
- WizardForm.cs
- TextEffect.cs
- TemplateField.cs
- MarkupExtensionParser.cs
- SystemIPv4InterfaceProperties.cs
- XMLSyntaxException.cs
- TemplateParser.cs
- RuntimeConfigurationRecord.cs
- GenericTextProperties.cs
- HostProtectionException.cs
- ScriptComponentDescriptor.cs
- RankException.cs
- AddIn.cs