Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / MS / Internal / PartialArray.cs / 1 / PartialArray.cs
//----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Description: The PartialArray struct is used when the developer needs to pass a CLR array range to
// a function that takes generic IList interface. For cases when the whole array needs to be passed,
// CLR array already implements IList.
//
//
// History:
// 06/25/2004 : mleonov - Created
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using SR = MS.Internal.PresentationCore.SR;
using SRID = MS.Internal.PresentationCore.SRID;
namespace MS.Internal
{
///
/// The PartialArray struct is used when someone needs to pass a CLR array range to
/// a function that takes generic IList interface. For cases when the whole array needs to be passed,
/// CLR array already implements IList.
///
internal struct PartialArray : IList
{
private T[] _array;
private int _initialIndex;
private int _count;
public PartialArray(T[] array, int initialIndex, int count)
{
// make sure early that the caller didn't miscalculate index and count
Debug.Assert(initialIndex >= 0 && initialIndex + count <= array.Length);
_array = array;
_initialIndex = initialIndex;
_count = count;
}
///
/// Convenience helper for passing the whole array.
///
///
public PartialArray(T[] array) : this(array, 0, array.Length)
{}
#region IList Members
public bool IsReadOnly
{
get
{
return false;
}
}
public bool Contains(T item)
{
return IndexOf(item) >= 0;
}
public bool IsFixedSize
{
get
{
return true;
}
}
public bool Remove(T item)
{
throw new NotSupportedException(SR.Get(SRID.CollectionIsFixedSize));
}
public void RemoveAt(int index)
{
throw new NotSupportedException(SR.Get(SRID.CollectionIsFixedSize));
}
public void Clear()
{
throw new NotSupportedException();
}
public void Add(T item)
{
throw new NotSupportedException(SR.Get(SRID.CollectionIsFixedSize));
}
public void Insert(int index, T item)
{
throw new NotSupportedException(SR.Get(SRID.CollectionIsFixedSize));
}
public T this[int index]
{
get
{
return _array[index + _initialIndex];
}
set
{
_array[index + _initialIndex] = value;
}
}
public int IndexOf(T item)
{
int index = Array.IndexOf(_array, item, _initialIndex, _count);
if (index >= 0)
{
return index - _initialIndex;
}
else
{
return -1;
}
}
#endregion
#region ICollection Members
public int Count
{
get
{
return _count;
}
}
public void CopyTo(T[] array, int arrayIndex)
{
// parameter validations
if (array == null)
{
throw new ArgumentNullException("array");
}
if (array.Rank != 1)
{
throw new ArgumentException(
SR.Get(SRID.Collection_CopyTo_ArrayCannotBeMultidimensional),
"array");
}
if (arrayIndex < 0)
{
throw new ArgumentOutOfRangeException("arrayIndex");
}
if (arrayIndex >= array.Length)
{
throw new ArgumentException(
SR.Get(
SRID.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength,
"arrayIndex",
"array"),
"arrayIndex");
}
if ((array.Length - Count - arrayIndex) < 0)
{
throw new ArgumentException(
SR.Get(
SRID.Collection_CopyTo_NumberOfElementsExceedsArrayLength,
"arrayIndex",
"array"));
}
// do the copying here
for (int i = 0; i < Count; i++)
{
array[arrayIndex + i] = this[i];
}
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
for (int i = 0; i < Count; i++)
{
yield return this[i];
}
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)this).GetEnumerator();
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Description: The PartialArray struct is used when the developer needs to pass a CLR array range to
// a function that takes generic IList interface. For cases when the whole array needs to be passed,
// CLR array already implements IList.
//
//
// History:
// 06/25/2004 : mleonov - Created
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using SR = MS.Internal.PresentationCore.SR;
using SRID = MS.Internal.PresentationCore.SRID;
namespace MS.Internal
{
///
/// The PartialArray struct is used when someone needs to pass a CLR array range to
/// a function that takes generic IList interface. For cases when the whole array needs to be passed,
/// CLR array already implements IList.
///
internal struct PartialArray : IList
{
private T[] _array;
private int _initialIndex;
private int _count;
public PartialArray(T[] array, int initialIndex, int count)
{
// make sure early that the caller didn't miscalculate index and count
Debug.Assert(initialIndex >= 0 && initialIndex + count <= array.Length);
_array = array;
_initialIndex = initialIndex;
_count = count;
}
///
/// Convenience helper for passing the whole array.
///
///
public PartialArray(T[] array) : this(array, 0, array.Length)
{}
#region IList Members
public bool IsReadOnly
{
get
{
return false;
}
}
public bool Contains(T item)
{
return IndexOf(item) >= 0;
}
public bool IsFixedSize
{
get
{
return true;
}
}
public bool Remove(T item)
{
throw new NotSupportedException(SR.Get(SRID.CollectionIsFixedSize));
}
public void RemoveAt(int index)
{
throw new NotSupportedException(SR.Get(SRID.CollectionIsFixedSize));
}
public void Clear()
{
throw new NotSupportedException();
}
public void Add(T item)
{
throw new NotSupportedException(SR.Get(SRID.CollectionIsFixedSize));
}
public void Insert(int index, T item)
{
throw new NotSupportedException(SR.Get(SRID.CollectionIsFixedSize));
}
public T this[int index]
{
get
{
return _array[index + _initialIndex];
}
set
{
_array[index + _initialIndex] = value;
}
}
public int IndexOf(T item)
{
int index = Array.IndexOf(_array, item, _initialIndex, _count);
if (index >= 0)
{
return index - _initialIndex;
}
else
{
return -1;
}
}
#endregion
#region ICollection Members
public int Count
{
get
{
return _count;
}
}
public void CopyTo(T[] array, int arrayIndex)
{
// parameter validations
if (array == null)
{
throw new ArgumentNullException("array");
}
if (array.Rank != 1)
{
throw new ArgumentException(
SR.Get(SRID.Collection_CopyTo_ArrayCannotBeMultidimensional),
"array");
}
if (arrayIndex < 0)
{
throw new ArgumentOutOfRangeException("arrayIndex");
}
if (arrayIndex >= array.Length)
{
throw new ArgumentException(
SR.Get(
SRID.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength,
"arrayIndex",
"array"),
"arrayIndex");
}
if ((array.Length - Count - arrayIndex) < 0)
{
throw new ArgumentException(
SR.Get(
SRID.Collection_CopyTo_NumberOfElementsExceedsArrayLength,
"arrayIndex",
"array"));
}
// do the copying here
for (int i = 0; i < Count; i++)
{
array[arrayIndex + i] = this[i];
}
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
for (int i = 0; i < Count; i++)
{
yield return this[i];
}
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)this).GetEnumerator();
}
#endregion
}
}
// 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
- AdornerPresentationContext.cs
- TextSchema.cs
- DataTableNewRowEvent.cs
- WebUtil.cs
- WebPartDisplayModeCollection.cs
- _LazyAsyncResult.cs
- EntityDataSourceReferenceGroup.cs
- Help.cs
- DecimalAnimationBase.cs
- DataViewSettingCollection.cs
- ErrorEventArgs.cs
- AsymmetricAlgorithm.cs
- DropShadowEffect.cs
- ConfigViewGenerator.cs
- XmlRawWriterWrapper.cs
- ContextStack.cs
- AsymmetricAlgorithm.cs
- StorageMappingItemLoader.cs
- IMembershipProvider.cs
- PackagePartCollection.cs
- KeyPressEvent.cs
- MimeTypeMapper.cs
- FormViewPagerRow.cs
- PreviewKeyDownEventArgs.cs
- XPathNavigatorKeyComparer.cs
- FixedPage.cs
- DataKey.cs
- FormatterServices.cs
- StrongNamePublicKeyBlob.cs
- DrawingContextWalker.cs
- PeerCustomResolverSettings.cs
- DockProviderWrapper.cs
- DetailsViewDeleteEventArgs.cs
- ClientSettingsStore.cs
- ConsumerConnectionPoint.cs
- GridViewSelectEventArgs.cs
- TextTreeFixupNode.cs
- BitmapEffectInputConnector.cs
- RetrieveVirtualItemEventArgs.cs
- CommandField.cs
- GcSettings.cs
- SqlDataSourceTableQuery.cs
- Pens.cs
- Message.cs
- WebPartConnectionsConfigureVerb.cs
- ChannelFactoryBase.cs
- ExpressionBuilder.cs
- SafeNativeMethods.cs
- LinqDataView.cs
- InplaceBitmapMetadataWriter.cs
- RegisteredDisposeScript.cs
- OutputCacheProfile.cs
- Preprocessor.cs
- SQLDateTime.cs
- DropShadowBitmapEffect.cs
- GradientSpreadMethodValidation.cs
- StorageModelBuildProvider.cs
- SqlProcedureAttribute.cs
- SerialErrors.cs
- VerificationAttribute.cs
- Span.cs
- SapiRecognizer.cs
- OracleMonthSpan.cs
- TableRowCollection.cs
- WindowVisualStateTracker.cs
- SafeLibraryHandle.cs
- WrappedKeySecurityToken.cs
- StreamingContext.cs
- SqlError.cs
- StickyNoteHelper.cs
- SecurityAlgorithmSuite.cs
- MenuItem.cs
- FixedSOMContainer.cs
- SiteMapDataSourceView.cs
- DBPropSet.cs
- ClientCultureInfo.cs
- PropertyEmitter.cs
- EntityDesignerDataSourceView.cs
- DefaultValueAttribute.cs
- DataGridViewLayoutData.cs
- TextElement.cs
- PartialTrustHelpers.cs
- UIPropertyMetadata.cs
- bidPrivateBase.cs
- OleDbInfoMessageEvent.cs
- ReturnEventArgs.cs
- QuotedPrintableStream.cs
- MetabaseServerConfig.cs
- Typography.cs
- DataSourceHelper.cs
- DataGridViewHitTestInfo.cs
- TreeViewDesigner.cs
- CriticalFinalizerObject.cs
- FixedBufferAttribute.cs
- UidManager.cs
- Attributes.cs
- WebPartUtil.cs
- DefaultPropertyAttribute.cs
- TailPinnedEventArgs.cs
- TimelineClockCollection.cs