Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Shared / MS / Internal / PartialList.cs / 1305600 / PartialList.cs
//----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Description: PartialList is used when the developer needs to pass an IList range to
// a function that takes generic IList interface.
//
//
// History:
// 06/25/2004 : mleonov - Created
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace MS.Internal
{
///
/// PartialList is used when someone needs to pass an IList range to
/// a function that takes generic IList interface. It implemented a read-only subset of IList.
///
internal class PartialList : IList
{
private IList _list;
private int _initialIndex;
private int _count;
///
/// Convenience constructor for taking in an entire list. Useful for creating a read-only
/// version of the list.
///
public PartialList(IList list)
{
_list = list;
_initialIndex = 0;
_count = list.Count;
}
public PartialList(IList list, int initialIndex, int count)
{
// make sure early that the caller didn't miscalculate index and count
Debug.Assert(initialIndex >= 0 && initialIndex + count <= list.Count);
_list = list;
_initialIndex = initialIndex;
_count = count;
}
#if !PRESENTATION_CORE
///
/// Creates new PartialList object only for true partial ranges.
/// Otherwise, returns the original list.
///
public static IList Create(IList list, int initialIndex, int count)
{
if (list == null)
return null;
if (initialIndex == 0 && count == list.Count)
return list;
return new PartialList(list, initialIndex, count);
}
#endif
#region IList Members
public void RemoveAt(int index)
{
// PartialList is read only.
throw new NotSupportedException();
}
public void Insert(int index, T item)
{
// PartialList is read only.
throw new NotSupportedException();
}
public T this[int index]
{
get
{
return _list[index + _initialIndex];
}
set
{
// PartialList is read only.
throw new NotSupportedException();
}
}
public int IndexOf(T item)
{
int index = _list.IndexOf(item);
if (index == -1 || index < _initialIndex || index - _initialIndex >= _count)
return -1;
return index - _initialIndex;
}
#endregion
#region ICollection Members
public bool IsReadOnly
{
get
{
return true;
}
}
public void Clear()
{
// PartialList is read only.
throw new NotSupportedException();
}
public void Add(T item)
{
// PartialList is read only.
throw new NotSupportedException();
}
public bool Contains(T item)
{
return IndexOf(item) != -1;
}
public bool Remove(T item)
{
// PartialList is read only.
throw new NotSupportedException();
}
public int Count
{
get
{
return _count;
}
}
public void CopyTo(T[] array, int arrayIndex)
{
if (arrayIndex < 0)
throw new ArgumentOutOfRangeException("arrayIndex");
for (int i = 0; i < _count; ++i)
array[arrayIndex + i] = this[i];
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
for (int i = _initialIndex; i < _initialIndex + _count; ++i)
yield return _list[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: PartialList is used when the developer needs to pass an IList range to
// a function that takes generic IList interface.
//
//
// History:
// 06/25/2004 : mleonov - Created
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace MS.Internal
{
///
/// PartialList is used when someone needs to pass an IList range to
/// a function that takes generic IList interface. It implemented a read-only subset of IList.
///
internal class PartialList : IList
{
private IList _list;
private int _initialIndex;
private int _count;
///
/// Convenience constructor for taking in an entire list. Useful for creating a read-only
/// version of the list.
///
public PartialList(IList list)
{
_list = list;
_initialIndex = 0;
_count = list.Count;
}
public PartialList(IList list, int initialIndex, int count)
{
// make sure early that the caller didn't miscalculate index and count
Debug.Assert(initialIndex >= 0 && initialIndex + count <= list.Count);
_list = list;
_initialIndex = initialIndex;
_count = count;
}
#if !PRESENTATION_CORE
///
/// Creates new PartialList object only for true partial ranges.
/// Otherwise, returns the original list.
///
public static IList Create(IList list, int initialIndex, int count)
{
if (list == null)
return null;
if (initialIndex == 0 && count == list.Count)
return list;
return new PartialList(list, initialIndex, count);
}
#endif
#region IList Members
public void RemoveAt(int index)
{
// PartialList is read only.
throw new NotSupportedException();
}
public void Insert(int index, T item)
{
// PartialList is read only.
throw new NotSupportedException();
}
public T this[int index]
{
get
{
return _list[index + _initialIndex];
}
set
{
// PartialList is read only.
throw new NotSupportedException();
}
}
public int IndexOf(T item)
{
int index = _list.IndexOf(item);
if (index == -1 || index < _initialIndex || index - _initialIndex >= _count)
return -1;
return index - _initialIndex;
}
#endregion
#region ICollection Members
public bool IsReadOnly
{
get
{
return true;
}
}
public void Clear()
{
// PartialList is read only.
throw new NotSupportedException();
}
public void Add(T item)
{
// PartialList is read only.
throw new NotSupportedException();
}
public bool Contains(T item)
{
return IndexOf(item) != -1;
}
public bool Remove(T item)
{
// PartialList is read only.
throw new NotSupportedException();
}
public int Count
{
get
{
return _count;
}
}
public void CopyTo(T[] array, int arrayIndex)
{
if (arrayIndex < 0)
throw new ArgumentOutOfRangeException("arrayIndex");
for (int i = 0; i < _count; ++i)
array[arrayIndex + i] = this[i];
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
for (int i = _initialIndex; i < _initialIndex + _count; ++i)
yield return _list[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
- IERequestCache.cs
- MD5CryptoServiceProvider.cs
- ServiceObjectContainer.cs
- DataGridViewCellLinkedList.cs
- ListItem.cs
- InternalBufferManager.cs
- CommandTreeTypeHelper.cs
- StylusDevice.cs
- ListBoxChrome.cs
- XmlBoundElement.cs
- ClassHandlersStore.cs
- HttpConfigurationContext.cs
- SystemResourceKey.cs
- ColorDialog.cs
- AppDomainProtocolHandler.cs
- Pair.cs
- XmlLangPropertyAttribute.cs
- MemberDescriptor.cs
- OutputCacheModule.cs
- AngleUtil.cs
- TextRangeBase.cs
- DataGridHeaderBorder.cs
- DbFunctionCommandTree.cs
- ResourceAttributes.cs
- StylusEventArgs.cs
- ClientSideProviderDescription.cs
- BitmapEffectInputData.cs
- ApplicationManager.cs
- ActivationServices.cs
- ObjectDataSourceStatusEventArgs.cs
- NativeMethods.cs
- TreeViewImageKeyConverter.cs
- CallContext.cs
- InstanceNameConverter.cs
- HtmlGenericControl.cs
- SignedXml.cs
- AliasGenerator.cs
- FileDialog_Vista_Interop.cs
- DataControlButton.cs
- RegexFCD.cs
- validation.cs
- UrlAuthFailedErrorFormatter.cs
- CodeNamespaceImportCollection.cs
- XmlStreamStore.cs
- Options.cs
- ImageCodecInfoPrivate.cs
- SafeEventLogWriteHandle.cs
- SQLBytesStorage.cs
- MimePart.cs
- SettingsProperty.cs
- ObjectDataSourceView.cs
- OutputChannelBinder.cs
- ScriptResourceAttribute.cs
- XmlWriterTraceListener.cs
- RenderOptions.cs
- QueryOutputWriter.cs
- FontDriver.cs
- XmlILAnnotation.cs
- keycontainerpermission.cs
- InvalidOleVariantTypeException.cs
- KernelTypeValidation.cs
- CombinedGeometry.cs
- SchemeSettingElement.cs
- WinFormsSpinner.cs
- RawAppCommandInputReport.cs
- StyleBamlTreeBuilder.cs
- XamlPathDataSerializer.cs
- StatusBarDrawItemEvent.cs
- MatrixKeyFrameCollection.cs
- StringArrayConverter.cs
- SafeIUnknown.cs
- DockingAttribute.cs
- NameNode.cs
- DataRecord.cs
- Deflater.cs
- AsymmetricCryptoHandle.cs
- ToolStripSettings.cs
- SqlInternalConnection.cs
- WebPartConnection.cs
- MethodExpr.cs
- UniqueSet.cs
- BinaryParser.cs
- ExtensionWindowHeader.cs
- FragmentQuery.cs
- OpenFileDialog.cs
- JpegBitmapEncoder.cs
- ClickablePoint.cs
- AppModelKnownContentFactory.cs
- PipelineComponent.cs
- DbModificationClause.cs
- InputProviderSite.cs
- XPathNavigatorReader.cs
- HtmlLiteralTextAdapter.cs
- LinearGradientBrush.cs
- SiblingIterators.cs
- CopyOnWriteList.cs
- WorkflowItemsPresenter.cs
- HMACSHA256.cs
- TransportBindingElementImporter.cs
- CompressionTracing.cs