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
- __Filters.cs
- EnumerableRowCollectionExtensions.cs
- RightsManagementPermission.cs
- CompressEmulationStream.cs
- GlyphCollection.cs
- CustomAttributeFormatException.cs
- HtmlInputReset.cs
- Maps.cs
- StrongTypingException.cs
- RestHandlerFactory.cs
- BehaviorService.cs
- EntityCollection.cs
- ItemList.cs
- HyperLinkStyle.cs
- ListViewContainer.cs
- CellParagraph.cs
- UnitySerializationHolder.cs
- MachineSettingsSection.cs
- StylusPointCollection.cs
- AutomationEvent.cs
- Evaluator.cs
- IgnorePropertiesAttribute.cs
- ExpressionNormalizer.cs
- HttpRequestMessageProperty.cs
- AnchoredBlock.cs
- FactoryGenerator.cs
- TransformerInfoCollection.cs
- AuthorizationSection.cs
- CompiledQuery.cs
- DataSourceCache.cs
- Queue.cs
- UInt32Storage.cs
- Point3DCollectionValueSerializer.cs
- TableRowCollection.cs
- Viewport2DVisual3D.cs
- TTSEvent.cs
- MatrixTransform3D.cs
- _emptywebproxy.cs
- sqlcontext.cs
- CfgSemanticTag.cs
- FormsAuthenticationCredentials.cs
- TransformerTypeCollection.cs
- ResolveResponseInfo.cs
- DataGridViewLinkColumn.cs
- Cursors.cs
- X509ChainPolicy.cs
- ThousandthOfEmRealDoubles.cs
- DateTimeUtil.cs
- DetailsViewRowCollection.cs
- DataException.cs
- HtmlCommandAdapter.cs
- BinaryWriter.cs
- SchemaImporterExtensionElement.cs
- Size3DConverter.cs
- KeyNotFoundException.cs
- XPathNavigator.cs
- VirtualPathUtility.cs
- WebEventCodes.cs
- DefaultMemberAttribute.cs
- XmlUtil.cs
- DesignerVerbCollection.cs
- RunClient.cs
- LayoutEngine.cs
- LinearGradientBrush.cs
- Encoder.cs
- PageParserFilter.cs
- Parameter.cs
- PageCatalogPart.cs
- MouseEvent.cs
- sqlcontext.cs
- DecoderFallbackWithFailureFlag.cs
- ConfigXmlReader.cs
- LinqDataSourceDeleteEventArgs.cs
- _LazyAsyncResult.cs
- _HeaderInfo.cs
- XmlDictionary.cs
- ItemsControl.cs
- ReflectionServiceProvider.cs
- RoutingBehavior.cs
- EncryptedData.cs
- DrawingContext.cs
- _SslSessionsCache.cs
- RequestSecurityToken.cs
- ImpersonationContext.cs
- WebPartActionVerb.cs
- WindowsToolbar.cs
- DiagnosticsConfiguration.cs
- WebResourceAttribute.cs
- WindowsImpersonationContext.cs
- EmbeddedMailObject.cs
- arc.cs
- ReceiveReply.cs
- DbConnectionHelper.cs
- CompiledQueryCacheEntry.cs
- SetIterators.cs
- FocusWithinProperty.cs
- TimeSpanOrInfiniteValidator.cs
- ValueChangedEventManager.cs
- ResourceReferenceKeyNotFoundException.cs
- DispatcherObject.cs