Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / 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
- DataControlFieldHeaderCell.cs
- Publisher.cs
- PointAnimationClockResource.cs
- SafeEventLogReadHandle.cs
- CodeConstructor.cs
- AttributeQuery.cs
- PerfProviderCollection.cs
- _FtpDataStream.cs
- DataServiceQueryException.cs
- figurelengthconverter.cs
- TextServicesManager.cs
- SamlAuthorityBinding.cs
- DataServiceResponse.cs
- DataTableReader.cs
- UshortList2.cs
- _OverlappedAsyncResult.cs
- LinkClickEvent.cs
- ValidatorCompatibilityHelper.cs
- HandlerBase.cs
- GridViewCancelEditEventArgs.cs
- PeerNodeTraceRecord.cs
- ProxySimple.cs
- XmlUtilWriter.cs
- RTLAwareMessageBox.cs
- JournalNavigationScope.cs
- DbConnectionPoolCounters.cs
- DesignerSerializationVisibilityAttribute.cs
- DetailsViewUpdatedEventArgs.cs
- RSAPKCS1SignatureFormatter.cs
- XmlDictionaryWriter.cs
- SmiConnection.cs
- CacheOutputQuery.cs
- OleDbDataReader.cs
- ReaderWriterLockWrapper.cs
- Annotation.cs
- printdlgexmarshaler.cs
- PropertyTabChangedEvent.cs
- NeutralResourcesLanguageAttribute.cs
- JoinElimination.cs
- EventWaitHandle.cs
- AspProxy.cs
- WCFServiceClientProxyGenerator.cs
- WebConfigurationHost.cs
- ValidatingReaderNodeData.cs
- PhonemeConverter.cs
- FloaterBaseParagraph.cs
- HtmlProps.cs
- SystemResourceHost.cs
- Listbox.cs
- SecurityContextSecurityToken.cs
- KeyInterop.cs
- DiscoveryDefaults.cs
- HostingEnvironmentSection.cs
- NumericUpDownAccelerationCollection.cs
- OSEnvironmentHelper.cs
- CustomSignedXml.cs
- COAUTHIDENTITY.cs
- BackStopAuthenticationModule.cs
- PathFigureCollection.cs
- XAMLParseException.cs
- ParagraphVisual.cs
- WmlPageAdapter.cs
- WebServiceClientProxyGenerator.cs
- BitmapEffectGeneralTransform.cs
- ObjectSet.cs
- FixedSchema.cs
- SetStateDesigner.cs
- VScrollProperties.cs
- SignatureResourcePool.cs
- LinkArea.cs
- TemplateKeyConverter.cs
- TemplateNameScope.cs
- SystemIcmpV4Statistics.cs
- VisualTransition.cs
- StorageInfo.cs
- EdmComplexTypeAttribute.cs
- TimeoutException.cs
- D3DImage.cs
- MethodCallConverter.cs
- ValidatingReaderNodeData.cs
- AsyncCompletedEventArgs.cs
- ValueType.cs
- AttributeCollection.cs
- ListParagraph.cs
- EventDescriptorCollection.cs
- ExpanderAutomationPeer.cs
- InkPresenterAutomationPeer.cs
- GridViewEditEventArgs.cs
- WeakRefEnumerator.cs
- Transform3DGroup.cs
- AlignmentYValidation.cs
- XmlWrappingReader.cs
- TargetPerspective.cs
- SafeNativeMethods.cs
- EdmProperty.cs
- TextRunCacheImp.cs
- StateManagedCollection.cs
- UrlMappingsSection.cs
- ExtentCqlBlock.cs
- CallSite.cs