Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Collections / ObjectModel / Collection.cs / 1305376 / Collection.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// [....]
//
namespace System.Collections.ObjectModel
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime;
[Serializable]
[System.Runtime.InteropServices.ComVisible(false)]
[DebuggerTypeProxy(typeof(Mscorlib_CollectionDebugView<>))]
[DebuggerDisplay("Count = {Count}")]
public class Collection: IList, IList
{
IList items;
[NonSerialized]
private Object _syncRoot;
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public Collection() {
items = new List();
}
public Collection(IList list) {
if (list == null) {
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list);
}
items = list;
}
public int Count {
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get { return items.Count; }
}
protected IList Items {
get { return items; }
}
public T this[int index] {
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
get { return items[index]; }
set {
if( items.IsReadOnly) {
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
}
if (index < 0 || index >= items.Count) {
ThrowHelper.ThrowArgumentOutOfRangeException();
}
SetItem(index, value);
}
}
public void Add(T item) {
if( items.IsReadOnly) {
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
}
int index = items.Count;
InsertItem(index, item);
}
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public void Clear() {
if( items.IsReadOnly) {
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
}
ClearItems();
}
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public void CopyTo(T[] array, int index) {
items.CopyTo(array, index);
}
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public bool Contains(T item) {
return items.Contains(item);
}
public IEnumerator GetEnumerator() {
return items.GetEnumerator();
}
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
public int IndexOf(T item) {
return items.IndexOf(item);
}
public void Insert(int index, T item) {
if (items.IsReadOnly) {
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
}
if (index < 0 || index > items.Count) {
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
}
InsertItem(index, item);
}
public bool Remove(T item) {
if( items.IsReadOnly) {
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
}
int index = items.IndexOf(item);
if (index < 0) return false;
RemoveItem(index);
return true;
}
public void RemoveAt(int index) {
if( items.IsReadOnly) {
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
}
if (index < 0 || index >= items.Count) {
ThrowHelper.ThrowArgumentOutOfRangeException();
}
RemoveItem(index);
}
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
protected virtual void ClearItems() {
items.Clear();
}
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
protected virtual void InsertItem(int index, T item) {
items.Insert(index, item);
}
#if !FEATURE_CORECLR
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
#endif
protected virtual void RemoveItem(int index) {
items.RemoveAt(index);
}
protected virtual void SetItem(int index, T item) {
items[index] = item;
}
bool ICollection.IsReadOnly {
get {
return items.IsReadOnly;
}
}
IEnumerator IEnumerable.GetEnumerator() {
return ((IEnumerable)items).GetEnumerator();
}
bool ICollection.IsSynchronized {
get { return false; }
}
object ICollection.SyncRoot {
get {
if( _syncRoot == null) {
ICollection c = items as ICollection;
if( c != null) {
_syncRoot = c.SyncRoot;
}
else {
System.Threading.Interlocked.CompareExchange
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataServiceHost.cs
- UnconditionalPolicy.cs
- DateTimeFormat.cs
- Timer.cs
- TrustManagerMoreInformation.cs
- ThicknessConverter.cs
- SessionStateSection.cs
- ProcessHostMapPath.cs
- AssemblyHash.cs
- EncryptedHeader.cs
- SchemaImporter.cs
- TrackingDataItem.cs
- ResXFileRef.cs
- BookmarkResumptionRecord.cs
- CustomAttributeSerializer.cs
- Single.cs
- x509utils.cs
- InputProcessorProfilesLoader.cs
- WindowClosedEventArgs.cs
- AuthenticateEventArgs.cs
- ColumnReorderedEventArgs.cs
- Visual3DCollection.cs
- GregorianCalendar.cs
- SetterBaseCollection.cs
- _SpnDictionary.cs
- CapabilitiesAssignment.cs
- TableLayoutSettings.cs
- SqlConnectionHelper.cs
- ConfigPathUtility.cs
- StrokeCollectionDefaultValueFactory.cs
- RijndaelManagedTransform.cs
- TitleStyle.cs
- TextElementCollectionHelper.cs
- OleDbError.cs
- HttpProfileGroupBase.cs
- SynchronizedDisposablePool.cs
- EncoderExceptionFallback.cs
- EraserBehavior.cs
- _SslSessionsCache.cs
- MetadataCollection.cs
- Expression.cs
- TextFragmentEngine.cs
- HierarchicalDataTemplate.cs
- IndexedString.cs
- DocComment.cs
- WinFormsSecurity.cs
- XsltLibrary.cs
- FileAuthorizationModule.cs
- Stopwatch.cs
- CollectionViewGroupInternal.cs
- ConfigurationErrorsException.cs
- DocumentPageHost.cs
- DataGridColumnCollection.cs
- ApplicationServiceManager.cs
- ValidationError.cs
- ErrorFormatterPage.cs
- DataConnectionHelper.cs
- WindowsFormsHost.cs
- OleDbException.cs
- CodeVariableReferenceExpression.cs
- PackWebResponse.cs
- SynchronizingStream.cs
- CodeSnippetExpression.cs
- AttachedPropertyMethodSelector.cs
- OleDbFactory.cs
- FreezableCollection.cs
- KerberosReceiverSecurityToken.cs
- CryptoProvider.cs
- PrePrepareMethodAttribute.cs
- TreeViewImageIndexConverter.cs
- PagerSettings.cs
- TrustSection.cs
- SettingsBindableAttribute.cs
- ParagraphResult.cs
- Sql8ConformanceChecker.cs
- FixedSOMSemanticBox.cs
- XmlCharCheckingWriter.cs
- TriggerActionCollection.cs
- CodeCatchClause.cs
- MultipartContentParser.cs
- LogArchiveSnapshot.cs
- UIPermission.cs
- ComponentChangingEvent.cs
- TrackBar.cs
- TCPListener.cs
- BinaryWriter.cs
- IndexedGlyphRun.cs
- ComboBox.cs
- QilNode.cs
- WebBrowsableAttribute.cs
- DetailsViewDesigner.cs
- QilInvokeLateBound.cs
- Stylus.cs
- SinglePageViewer.cs
- XslTransform.cs
- TokenBasedSet.cs
- Win32Native.cs
- Properties.cs
- ImageMapEventArgs.cs
- DrawingGroupDrawingContext.cs