Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / Microsoft / Scripting / Utils / ReadOnlyDictionary.cs / 1305376 / ReadOnlyDictionary.cs
/* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Microsoft Public License. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Microsoft Public License, please send an email to * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Microsoft Public License. * * You must not remove this notice, or any other, from this software. * * * ***************************************************************************/ using System.Collections.Generic; using System.Linq.Expressions; #if SILVERLIGHT using System.Core; #endif namespace System.Dynamic.Utils { // Like ReadOnlyCollection: wraps an IDictionary in a read-only wrapper internal sealed class ReadOnlyDictionary : IDictionary { // For wrapping non-readonly Keys, Values collections // Not used for standard dictionaries, which return read-only Keys and Values private sealed class ReadOnlyWrapper : ICollection { // no idea why this warning is here [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] private readonly ICollection _collection; internal ReadOnlyWrapper(ICollection collection) { _collection = collection; } #region ICollection Members public void Add(T item) { throw Error.CollectionReadOnly(); } public void Clear() { throw Error.CollectionReadOnly(); } public bool Contains(T item) { return _collection.Contains(item); } public void CopyTo(T[] array, int arrayIndex) { _collection.CopyTo(array, arrayIndex); } public int Count { get { return _collection.Count; } } public bool IsReadOnly { get { return true; } } public bool Remove(T item) { throw Error.CollectionReadOnly(); } #endregion #region IEnumerable Members public IEnumerator GetEnumerator() { return _collection.GetEnumerator(); } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return _collection.GetEnumerator(); } #endregion } private readonly IDictionary _dict; internal ReadOnlyDictionary(IDictionary dict) { ReadOnlyDictionary rodict = dict as ReadOnlyDictionary ; _dict = (rodict != null) ? rodict._dict : dict; } #region IDictionary Members public bool ContainsKey(K key) { return _dict.ContainsKey(key); } public ICollection Keys { get { ICollection keys = _dict.Keys; if (!keys.IsReadOnly) { return new ReadOnlyWrapper (keys); } return keys; } } public bool TryGetValue(K key, out V value) { return _dict.TryGetValue(key, out value); } public ICollection Values { get { ICollection values = _dict.Values; if (!values.IsReadOnly) { return new ReadOnlyWrapper (values); } return values; } } public V this[K key] { get { return _dict[key]; } } void IDictionary .Add(K key, V value) { throw Error.CollectionReadOnly(); } bool IDictionary .Remove(K key) { throw Error.CollectionReadOnly(); } V IDictionary .this[K key] { get { return _dict[key]; } set { throw Error.CollectionReadOnly(); } } #endregion #region ICollection > Members public bool Contains(KeyValuePair item) { return _dict.Contains(item); } public void CopyTo(KeyValuePair [] array, int arrayIndex) { _dict.CopyTo(array, arrayIndex); } public int Count { get { return _dict.Count; } } public bool IsReadOnly { get { return true; } } void ICollection >.Add(KeyValuePair item) { throw Error.CollectionReadOnly(); } void ICollection >.Clear() { throw Error.CollectionReadOnly(); } bool ICollection >.Remove(KeyValuePair item) { throw Error.CollectionReadOnly(); } #endregion #region IEnumerable > Members public IEnumerator > GetEnumerator() { return _dict.GetEnumerator(); } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return _dict.GetEnumerator(); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Microsoft Public License. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Microsoft Public License, please send an email to * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Microsoft Public License. * * You must not remove this notice, or any other, from this software. * * * ***************************************************************************/ using System.Collections.Generic; using System.Linq.Expressions; #if SILVERLIGHT using System.Core; #endif namespace System.Dynamic.Utils { // Like ReadOnlyCollection : wraps an IDictionary in a read-only wrapper internal sealed class ReadOnlyDictionary : IDictionary { // For wrapping non-readonly Keys, Values collections // Not used for standard dictionaries, which return read-only Keys and Values private sealed class ReadOnlyWrapper : ICollection { // no idea why this warning is here [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] private readonly ICollection _collection; internal ReadOnlyWrapper(ICollection collection) { _collection = collection; } #region ICollection Members public void Add(T item) { throw Error.CollectionReadOnly(); } public void Clear() { throw Error.CollectionReadOnly(); } public bool Contains(T item) { return _collection.Contains(item); } public void CopyTo(T[] array, int arrayIndex) { _collection.CopyTo(array, arrayIndex); } public int Count { get { return _collection.Count; } } public bool IsReadOnly { get { return true; } } public bool Remove(T item) { throw Error.CollectionReadOnly(); } #endregion #region IEnumerable Members public IEnumerator GetEnumerator() { return _collection.GetEnumerator(); } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return _collection.GetEnumerator(); } #endregion } private readonly IDictionary _dict; internal ReadOnlyDictionary(IDictionary dict) { ReadOnlyDictionary rodict = dict as ReadOnlyDictionary ; _dict = (rodict != null) ? rodict._dict : dict; } #region IDictionary Members public bool ContainsKey(K key) { return _dict.ContainsKey(key); } public ICollection Keys { get { ICollection keys = _dict.Keys; if (!keys.IsReadOnly) { return new ReadOnlyWrapper (keys); } return keys; } } public bool TryGetValue(K key, out V value) { return _dict.TryGetValue(key, out value); } public ICollection Values { get { ICollection values = _dict.Values; if (!values.IsReadOnly) { return new ReadOnlyWrapper (values); } return values; } } public V this[K key] { get { return _dict[key]; } } void IDictionary .Add(K key, V value) { throw Error.CollectionReadOnly(); } bool IDictionary .Remove(K key) { throw Error.CollectionReadOnly(); } V IDictionary .this[K key] { get { return _dict[key]; } set { throw Error.CollectionReadOnly(); } } #endregion #region ICollection > Members public bool Contains(KeyValuePair item) { return _dict.Contains(item); } public void CopyTo(KeyValuePair [] array, int arrayIndex) { _dict.CopyTo(array, arrayIndex); } public int Count { get { return _dict.Count; } } public bool IsReadOnly { get { return true; } } void ICollection >.Add(KeyValuePair item) { throw Error.CollectionReadOnly(); } void ICollection >.Clear() { throw Error.CollectionReadOnly(); } bool ICollection >.Remove(KeyValuePair item) { throw Error.CollectionReadOnly(); } #endregion #region IEnumerable > Members public IEnumerator > GetEnumerator() { return _dict.GetEnumerator(); } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return _dict.GetEnumerator(); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- MultiSelectRootGridEntry.cs
- WorkflowViewService.cs
- DefinitionUpdate.cs
- XmlReaderSettings.cs
- PointValueSerializer.cs
- ReadOnlyDataSourceView.cs
- BitmapFrameDecode.cs
- SortQueryOperator.cs
- DeferredSelectedIndexReference.cs
- MoveSizeWinEventHandler.cs
- XmlC14NWriter.cs
- XmlILOptimizerVisitor.cs
- ColorDialog.cs
- CodeMethodReturnStatement.cs
- WorkflowValidationFailedException.cs
- CharacterBuffer.cs
- DateRangeEvent.cs
- Int16AnimationBase.cs
- ImageFormatConverter.cs
- SByteStorage.cs
- UniqueContractNameValidationBehavior.cs
- StylusPointDescription.cs
- RegistryKey.cs
- Point3DCollection.cs
- PeerDuplexChannelListener.cs
- ConnectionStringsExpressionBuilder.cs
- MultiTouchSystemGestureLogic.cs
- CodeSnippetExpression.cs
- MimeMapping.cs
- XsltFunctions.cs
- SrgsElementFactoryCompiler.cs
- OleDbRowUpdatedEvent.cs
- AuthenticatingEventArgs.cs
- DataStreamFromComStream.cs
- OleServicesContext.cs
- GACMembershipCondition.cs
- PublishLicense.cs
- ItemDragEvent.cs
- RoleGroup.cs
- ListBoxItemAutomationPeer.cs
- FontStyleConverter.cs
- GlobalEventManager.cs
- FormClosedEvent.cs
- ObjectHandle.cs
- QueryStringConverter.cs
- DoubleCollection.cs
- BackgroundFormatInfo.cs
- SrgsSubset.cs
- XmlDataCollection.cs
- Util.cs
- ExpanderAutomationPeer.cs
- ICollection.cs
- ButtonFieldBase.cs
- TypographyProperties.cs
- DataContractAttribute.cs
- xmlsaver.cs
- SqlExpressionNullability.cs
- Utils.cs
- ModuleElement.cs
- TextModifier.cs
- PlainXmlSerializer.cs
- NumberEdit.cs
- Propagator.JoinPropagator.cs
- MemberMaps.cs
- ServiceNameElementCollection.cs
- TextEditorTyping.cs
- IdentifierCollection.cs
- SQLRoleProvider.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- SqlFactory.cs
- Parser.cs
- ListItemsCollectionEditor.cs
- ChangeProcessor.cs
- ToolStripOverflow.cs
- PackageFilter.cs
- XpsPackagingException.cs
- LogPolicy.cs
- SQLStringStorage.cs
- GeneralTransform3DCollection.cs
- TimeManager.cs
- StringFunctions.cs
- CreateDataSourceDialog.cs
- PolyQuadraticBezierSegment.cs
- StrongNamePublicKeyBlob.cs
- DataGridColumnCollection.cs
- PointConverter.cs
- OpenTypeLayout.cs
- baseshape.cs
- Scheduling.cs
- CompModSwitches.cs
- CultureSpecificCharacterBufferRange.cs
- EventLog.cs
- FileSystemEventArgs.cs
- DrawingCollection.cs
- ArgumentNullException.cs
- WsiProfilesElementCollection.cs
- ToolStripItemRenderEventArgs.cs
- XamlStream.cs
- InheritablePropertyChangeInfo.cs
- WhiteSpaceTrimStringConverter.cs