Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / ImmutableCollection.cs / 1305376 / ImmutableCollection.cs
//---------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel { using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; // // A collection that can be made immutable by calling the // MakeReadOnly method. Once the collection is made read-only // Add, Remove and Clear methods will throw an exception // failing to add a item to the collection. // internal sealed class ImmutableCollection: Collection , IList , IList { bool isReadOnly = false; public void MakeReadOnly() { this.isReadOnly = true; } public bool IsReadOnly { get { return this.isReadOnly; } } protected override void ClearItems() { if (this.isReadOnly) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly))); base.ClearItems(); } protected override void InsertItem(int index, T item) { if (this.isReadOnly) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly))); base.InsertItem(index, item); } protected override void RemoveItem(int index) { if (this.isReadOnly) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly))); base.RemoveItem(index); } protected override void SetItem(int index, T item) { if (this.isReadOnly) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly))); base.SetItem(index, item); } bool ICollection .IsReadOnly { get { return this.isReadOnly; } } bool IList.IsReadOnly { get { return this.isReadOnly; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel { using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; // // A collection that can be made immutable by calling the // MakeReadOnly method. Once the collection is made read-only // Add, Remove and Clear methods will throw an exception // failing to add a item to the collection. // internal sealed class ImmutableCollection : Collection , IList , IList { bool isReadOnly = false; public void MakeReadOnly() { this.isReadOnly = true; } public bool IsReadOnly { get { return this.isReadOnly; } } protected override void ClearItems() { if (this.isReadOnly) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly))); base.ClearItems(); } protected override void InsertItem(int index, T item) { if (this.isReadOnly) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly))); base.InsertItem(index, item); } protected override void RemoveItem(int index) { if (this.isReadOnly) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly))); base.RemoveItem(index); } protected override void SetItem(int index, T item) { if (this.isReadOnly) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly))); base.SetItem(index, item); } bool ICollection .IsReadOnly { get { return this.isReadOnly; } } bool IList.IsReadOnly { get { return this.isReadOnly; } } } } // 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
- Trace.cs
- Task.cs
- ErasingStroke.cs
- CharEnumerator.cs
- DataGridViewImageCell.cs
- KoreanLunisolarCalendar.cs
- RefreshResponseInfo.cs
- NonParentingControl.cs
- WebBrowsableAttribute.cs
- LocalIdKeyIdentifierClause.cs
- EnumerableValidator.cs
- SafeMemoryMappedViewHandle.cs
- ContourSegment.cs
- SmiEventSink.cs
- CacheRequest.cs
- ToolStripDropDownMenu.cs
- RepeaterCommandEventArgs.cs
- ExpressionBuilder.cs
- SqlCommandSet.cs
- UnsafeNativeMethods.cs
- VisualBrush.cs
- SafeNativeMethods.cs
- IconBitmapDecoder.cs
- DropDownList.cs
- ButtonRenderer.cs
- PointAnimationClockResource.cs
- PassportAuthenticationEventArgs.cs
- DocumentXPathNavigator.cs
- TextRangeEdit.cs
- ConfigurationManagerHelper.cs
- Vars.cs
- ToolStripGrip.cs
- UnsafeNativeMethods.cs
- Parser.cs
- PropertyChangedEventManager.cs
- RadioButton.cs
- Utils.cs
- CommandDevice.cs
- ImageSourceConverter.cs
- PageParserFilter.cs
- CompositeControlDesigner.cs
- NativeMethods.cs
- PrintControllerWithStatusDialog.cs
- PackWebRequest.cs
- CommandEventArgs.cs
- OutputScopeManager.cs
- MethodBody.cs
- ObjRef.cs
- ComboBoxItem.cs
- WsiProfilesElement.cs
- OutputCacheSettings.cs
- VectorCollection.cs
- EventMetadata.cs
- PartialClassGenerationTaskInternal.cs
- ServiceDescriptionImporter.cs
- HtmlValidatorAdapter.cs
- LocalizableAttribute.cs
- DoubleAnimation.cs
- OdbcFactory.cs
- SerializerDescriptor.cs
- BulletedListEventArgs.cs
- CompModSwitches.cs
- StringAnimationBase.cs
- Pts.cs
- TypeConverter.cs
- ScriptDescriptor.cs
- CodeDefaultValueExpression.cs
- AddingNewEventArgs.cs
- HtmlElementErrorEventArgs.cs
- DesignerCategoryAttribute.cs
- InstallerTypeAttribute.cs
- KeyBinding.cs
- SafeNativeMethodsOther.cs
- UnitySerializationHolder.cs
- BindingMemberInfo.cs
- Connector.cs
- GlyphingCache.cs
- XmlResolver.cs
- KnownBoxes.cs
- VirtualDirectoryMappingCollection.cs
- AppDomainUnloadedException.cs
- StylusTip.cs
- TimeSpan.cs
- XmlSiteMapProvider.cs
- EventMap.cs
- WindowsScrollBarBits.cs
- AttributeInfo.cs
- FileDialog_Vista_Interop.cs
- DrawingAttributeSerializer.cs
- InnerItemCollectionView.cs
- Help.cs
- FrameworkObject.cs
- PrincipalPermission.cs
- ConnectionPoolManager.cs
- ReliableDuplexSessionChannel.cs
- CodeCastExpression.cs
- ColumnReorderedEventArgs.cs
- StreamUpdate.cs
- DataGridParentRows.cs
- Timer.cs