Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / SynchronizedReadOnlyCollection.cs / 1 / SynchronizedReadOnlyCollection.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Collections.Generic { using System; using System.Collections; using System.Diagnostics; using System.ServiceModel; [System.Runtime.InteropServices.ComVisible(false)] public class SynchronizedReadOnlyCollection: IList , IList { IList items; object sync; public SynchronizedReadOnlyCollection() { this.items = new List (); this.sync = new Object(); } public SynchronizedReadOnlyCollection(object syncRoot) { if (syncRoot == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("syncRoot")); this.items = new List (); this.sync = syncRoot; } public SynchronizedReadOnlyCollection(object syncRoot, IEnumerable list) { if (syncRoot == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("syncRoot")); if (list == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("list")); this.items = new List (list); this.sync = syncRoot; } public SynchronizedReadOnlyCollection(object syncRoot, params T[] list) { if (syncRoot == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("syncRoot")); if (list == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("list")); this.items = new List (list.Length); for (int i=0; i list, bool makeCopy) { if (syncRoot == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("syncRoot")); if (list == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("list")); if (makeCopy) this.items = new List (list); else this.items = list; this.sync = syncRoot; } public int Count { get { lock (this.sync) { return this.items.Count; } } } protected IList Items { get { return this.items; } } public T this[int index] { get { lock (this.sync) { return this.items[index]; } } } public bool Contains(T value) { lock (this.sync) { return this.items.Contains(value); } } public void CopyTo(T[] array, int index) { lock (this.sync) { this.items.CopyTo(array, index); } } public IEnumerator GetEnumerator() { lock (this.sync) { return this.items.GetEnumerator(); } } public int IndexOf(T value) { lock (this.sync) { return this.items.IndexOf(value); } } void ThrowReadOnly() { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.SFxCollectionReadOnly))); } bool ICollection .IsReadOnly { get { return true; } } T IList .this[int index] { get { return this[index]; } set { this.ThrowReadOnly(); } } void ICollection .Add(T value) { this.ThrowReadOnly(); } void ICollection .Clear() { this.ThrowReadOnly(); } bool ICollection .Remove(T value) { this.ThrowReadOnly(); return false; } void IList .Insert(int index, T value) { this.ThrowReadOnly(); } void IList .RemoveAt(int index) { this.ThrowReadOnly(); } bool ICollection.IsSynchronized { get { return true; } } object ICollection.SyncRoot { get { return this.sync; } } void ICollection.CopyTo(Array array, int index) { ICollection asCollection = this.items as ICollection; if (asCollection == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.SFxCopyToRequiresICollection))); lock (this.sync) { asCollection.CopyTo(array, index); } } IEnumerator IEnumerable.GetEnumerator() { lock (this.sync) { IEnumerable asEnumerable = this.items as IEnumerable; if (asEnumerable != null) return asEnumerable.GetEnumerator(); else return new EnumeratorAdapter(this.items); } } bool IList.IsFixedSize { get { return true; } } bool IList.IsReadOnly { get { return true; } } object IList.this[int index] { get { return this[index]; } set { this.ThrowReadOnly(); } } int IList.Add(object value) { this.ThrowReadOnly(); return 0; } void IList.Clear() { this.ThrowReadOnly(); } bool IList.Contains(object value) { VerifyValueType(value); return this.Contains((T)value); } int IList.IndexOf(object value) { VerifyValueType(value); return this.IndexOf((T)value); } void IList.Insert(int index, object value) { this.ThrowReadOnly(); } void IList.Remove(object value) { this.ThrowReadOnly(); } void IList.RemoveAt(int index) { this.ThrowReadOnly(); } static void VerifyValueType(object value) { if ((value is T) || (value == null && !typeof(T).IsValueType)) return; Type type = (value == null) ? typeof(Object) : value.GetType(); string message = SR.GetString(SR.SFxCollectionWrongType2, type.ToString(), typeof(T).ToString()); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(message)); } sealed class EnumeratorAdapter: IEnumerator, IDisposable { IList list; IEnumerator e; public EnumeratorAdapter(IList list) { this.list = list; this.e = list.GetEnumerator(); } public object Current { get { return e.Current; } } public bool MoveNext() { return e.MoveNext(); } public void Dispose() { e.Dispose(); } public void Reset() { e = list.GetEnumerator(); } } } } // 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
- Compiler.cs
- MatcherBuilder.cs
- StringStorage.cs
- SubstitutionDesigner.cs
- CharUnicodeInfo.cs
- BaseTemplateBuildProvider.cs
- TypeListConverter.cs
- AdornerDecorator.cs
- DockingAttribute.cs
- Drawing.cs
- X509SecurityToken.cs
- IChannel.cs
- __TransparentProxy.cs
- DataGridViewCellStyleContentChangedEventArgs.cs
- NativeMethodsOther.cs
- PathTooLongException.cs
- MetadataWorkspace.cs
- followingsibling.cs
- EntityDesignerDataSourceView.cs
- InterleavedZipPartStream.cs
- ConditionalDesigner.cs
- DemultiplexingClientMessageFormatter.cs
- ContextMarshalException.cs
- FixedTextPointer.cs
- ClientConvert.cs
- path.cs
- VirtualPathProvider.cs
- CounterCreationData.cs
- ApplicationBuildProvider.cs
- IntSecurity.cs
- RegexTree.cs
- DataGridColumn.cs
- XmlSchemaAttributeGroup.cs
- ImmutableClientRuntime.cs
- MimeReflector.cs
- MDIClient.cs
- InputManager.cs
- ContainerControl.cs
- LoggedException.cs
- ChannelManager.cs
- XPathConvert.cs
- SortKey.cs
- Model3D.cs
- BindableAttribute.cs
- FormViewUpdatedEventArgs.cs
- InkCanvasInnerCanvas.cs
- DbProviderFactories.cs
- MenuItemStyleCollectionEditor.cs
- EntityExpressionVisitor.cs
- WebBrowser.cs
- AncestorChangedEventArgs.cs
- EntityUtil.cs
- CqlWriter.cs
- AsyncContentLoadedEventArgs.cs
- SupportsEventValidationAttribute.cs
- GB18030Encoding.cs
- FixedSOMPageElement.cs
- GZipStream.cs
- SqlCacheDependencySection.cs
- StretchValidation.cs
- ImagingCache.cs
- DatatypeImplementation.cs
- HMACMD5.cs
- PropertyDescriptorComparer.cs
- ImageField.cs
- SecurityPolicySection.cs
- BitmapEffectDrawingContent.cs
- XamlTypeWithExplicitNamespace.cs
- CalendarDateChangedEventArgs.cs
- DesignerSerializationVisibilityAttribute.cs
- DataGridTableStyleMappingNameEditor.cs
- DataGridViewColumnTypeEditor.cs
- _TransmitFileOverlappedAsyncResult.cs
- TileModeValidation.cs
- GeneralTransform3DGroup.cs
- XmlNullResolver.cs
- UriSectionData.cs
- BrowserCapabilitiesCodeGenerator.cs
- SectionVisual.cs
- Parameter.cs
- ExtenderProviderService.cs
- BindingValueChangedEventArgs.cs
- FileInfo.cs
- RuntimeUtils.cs
- SettingsPropertyIsReadOnlyException.cs
- FormViewModeEventArgs.cs
- _BaseOverlappedAsyncResult.cs
- HierarchicalDataTemplate.cs
- ChannelToken.cs
- BitmapEffect.cs
- ProfileServiceManager.cs
- ListBindingConverter.cs
- CodeDirectionExpression.cs
- WebColorConverter.cs
- UnsafeNativeMethods.cs
- MessageQueueAccessControlEntry.cs
- DrawingContextDrawingContextWalker.cs
- NetMsmqBindingElement.cs
- VirtualizedItemPattern.cs
- WinEventHandler.cs