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
- XmlSerializerAssemblyAttribute.cs
- SQLInt32Storage.cs
- ProbeDuplexCD1AsyncResult.cs
- AssemblyFilter.cs
- configsystem.cs
- CustomExpression.cs
- DbConnectionInternal.cs
- base64Transforms.cs
- GlyphRun.cs
- ShaperBuffers.cs
- EdmComplexPropertyAttribute.cs
- VirtualizedItemPattern.cs
- CompilerErrorCollection.cs
- EdmRelationshipRoleAttribute.cs
- DefaultClaimSet.cs
- SerializationSectionGroup.cs
- XmlArrayAttribute.cs
- HMACMD5.cs
- IndexOutOfRangeException.cs
- Ray3DHitTestResult.cs
- WindowsTreeView.cs
- SafeRightsManagementSessionHandle.cs
- NameSpaceExtractor.cs
- CodeTypeReference.cs
- HttpCachePolicyWrapper.cs
- RelatedPropertyManager.cs
- _CookieModule.cs
- BindingList.cs
- BitmapEffectGroup.cs
- CharacterShapingProperties.cs
- CursorInteropHelper.cs
- _ListenerAsyncResult.cs
- XmlLangPropertyAttribute.cs
- XmlDataSource.cs
- DesignerMetadata.cs
- NavigationHelper.cs
- TagNameToTypeMapper.cs
- VisualTreeUtils.cs
- ProxyManager.cs
- unsafenativemethodstextservices.cs
- UnionCodeGroup.cs
- AssemblyResourceLoader.cs
- CheckPair.cs
- SlotInfo.cs
- ObjectDataSourceView.cs
- CompressedStack.cs
- ObjectDataSourceMethodEventArgs.cs
- HtmlTernaryTree.cs
- QuaternionAnimationBase.cs
- Zone.cs
- SystemColors.cs
- BitConverter.cs
- MSAAEventDispatcher.cs
- TransportBindingElement.cs
- RecordConverter.cs
- HijriCalendar.cs
- DisableDpiAwarenessAttribute.cs
- UriSection.cs
- SortedDictionary.cs
- CharKeyFrameCollection.cs
- X509SecurityTokenParameters.cs
- JoinSymbol.cs
- PropertyItem.cs
- XmlResolver.cs
- SiteMapNodeItemEventArgs.cs
- PersonalizationProvider.cs
- BuildDependencySet.cs
- CommandValueSerializer.cs
- BitmapEffect.cs
- PageContentAsyncResult.cs
- WorkerRequest.cs
- PeerInvitationResponse.cs
- elementinformation.cs
- LogicalTreeHelper.cs
- HttpFileCollectionBase.cs
- ProbeDuplex11AsyncResult.cs
- MonikerProxyAttribute.cs
- XamlTreeBuilder.cs
- DataGridViewColumnStateChangedEventArgs.cs
- ProfileProvider.cs
- ZipIOExtraFieldZip64Element.cs
- XPathQilFactory.cs
- COM2Properties.cs
- DnsEndPoint.cs
- IgnoreFlushAndCloseStream.cs
- XmlDataCollection.cs
- ExtensionDataObject.cs
- StorageAssociationTypeMapping.cs
- TextViewSelectionProcessor.cs
- ZipArchive.cs
- FullTextState.cs
- MultiBindingExpression.cs
- DecoderFallback.cs
- PrimitiveCodeDomSerializer.cs
- HwndSourceKeyboardInputSite.cs
- EdmToObjectNamespaceMap.cs
- ItemsControl.cs
- QueryInterceptorAttribute.cs
- EntitySqlQueryState.cs
- RowParagraph.cs