Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Shared / MS / Internal / GenericEnumerator.cs / 1 / GenericEnumerator.cs
//------------------------------------------------------------------------------
// Microsoft Avalon
// Copyright (c) Microsoft Corporation, 2001
//
// File: GenericEnumerator.cs
//-----------------------------------------------------------------------------
using System;
using System.Collections;
using System.Diagnostics;
using System.Windows;
using MS.Utility;
#if PRESENTATION_CORE
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
#else
using SR=System.Windows.SR;
using SRID=System.Windows.SRID;
#endif
namespace MS.Internal
{
///
/// GenericEnumerator
///
internal class GenericEnumerator : IEnumerator
{
#region Delegates
internal delegate int GetGenerationIDDelegate();
#endregion
#region Constructors
private GenericEnumerator()
{
}
internal GenericEnumerator(IList array, GetGenerationIDDelegate getGenerationID)
{
_array = array;
_count = _array.Count;
_position = -1;
_getGenerationID = getGenerationID;
_originalGenerationID = _getGenerationID();
}
#endregion
#region Private
private void VerifyCurrent()
{
if ( (-1 == _position)
|| (_position >= _count))
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_VerifyContext));
}
}
#endregion
#region IEnumerator
///
/// Returns the object at the current location of the key times list.
/// Use the strongly typed version instead.
///
object
IEnumerator.Current
{
get
{
VerifyCurrent();
return _current;
}
}
///
/// Move to the next value in the key times list
///
/// true if succeeded, false if at the end of the list
public bool MoveNext()
{
if (_getGenerationID() != _originalGenerationID)
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_CollectionChanged));
}
_position++;
if (_position >= _count)
{
_position = _count;
return false;
}
else
{
Debug.Assert(_position >= 0);
_current = _array[_position];
return true;
}
}
///
/// Move to the position before the first value in the list.
///
public void Reset()
{
if (_getGenerationID() != _originalGenerationID)
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_CollectionChanged));
}
else
{
_position = -1;
}
}
#endregion
#region Data
private IList _array;
private object _current;
private int _count;
private int _position;
private int _originalGenerationID;
private GetGenerationIDDelegate _getGenerationID;
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
// Microsoft Avalon
// Copyright (c) Microsoft Corporation, 2001
//
// File: GenericEnumerator.cs
//-----------------------------------------------------------------------------
using System;
using System.Collections;
using System.Diagnostics;
using System.Windows;
using MS.Utility;
#if PRESENTATION_CORE
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
#else
using SR=System.Windows.SR;
using SRID=System.Windows.SRID;
#endif
namespace MS.Internal
{
///
/// GenericEnumerator
///
internal class GenericEnumerator : IEnumerator
{
#region Delegates
internal delegate int GetGenerationIDDelegate();
#endregion
#region Constructors
private GenericEnumerator()
{
}
internal GenericEnumerator(IList array, GetGenerationIDDelegate getGenerationID)
{
_array = array;
_count = _array.Count;
_position = -1;
_getGenerationID = getGenerationID;
_originalGenerationID = _getGenerationID();
}
#endregion
#region Private
private void VerifyCurrent()
{
if ( (-1 == _position)
|| (_position >= _count))
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_VerifyContext));
}
}
#endregion
#region IEnumerator
///
/// Returns the object at the current location of the key times list.
/// Use the strongly typed version instead.
///
object
IEnumerator.Current
{
get
{
VerifyCurrent();
return _current;
}
}
///
/// Move to the next value in the key times list
///
/// true if succeeded, false if at the end of the list
public bool MoveNext()
{
if (_getGenerationID() != _originalGenerationID)
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_CollectionChanged));
}
_position++;
if (_position >= _count)
{
_position = _count;
return false;
}
else
{
Debug.Assert(_position >= 0);
_current = _array[_position];
return true;
}
}
///
/// Move to the position before the first value in the list.
///
public void Reset()
{
if (_getGenerationID() != _originalGenerationID)
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_CollectionChanged));
}
else
{
_position = -1;
}
}
#endregion
#region Data
private IList _array;
private object _current;
private int _count;
private int _position;
private int _originalGenerationID;
private GetGenerationIDDelegate _getGenerationID;
#endregion
}
}
// 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
- BamlTreeNode.cs
- RouteUrlExpressionBuilder.cs
- SqlMethodAttribute.cs
- ListBoxAutomationPeer.cs
- Types.cs
- ExceptionRoutedEventArgs.cs
- ImageAutomationPeer.cs
- OracleString.cs
- DataPagerCommandEventArgs.cs
- TimeStampChecker.cs
- UserControlBuildProvider.cs
- MsdtcWrapper.cs
- WindowsListViewScroll.cs
- CollectionViewGroup.cs
- LightweightEntityWrapper.cs
- InvalidCastException.cs
- NavigationCommands.cs
- OrderedEnumerableRowCollection.cs
- Label.cs
- ValidationPropertyAttribute.cs
- SchemaImporter.cs
- Size.cs
- ServiceNotStartedException.cs
- SettingsPropertyNotFoundException.cs
- NetCodeGroup.cs
- SqlXmlStorage.cs
- AlphabeticalEnumConverter.cs
- AutoGeneratedField.cs
- DataGridViewRowCollection.cs
- ToolStripSeparatorRenderEventArgs.cs
- Errors.cs
- Int32Converter.cs
- ComboBoxRenderer.cs
- PropertyPathConverter.cs
- ButtonBaseAutomationPeer.cs
- COM2TypeInfoProcessor.cs
- SpellCheck.cs
- DetailsView.cs
- MemberCollection.cs
- StructuredTypeEmitter.cs
- RectangleHotSpot.cs
- RoutedCommand.cs
- OracleNumber.cs
- PathFigureCollection.cs
- CalendarAutoFormat.cs
- MouseButtonEventArgs.cs
- QilUnary.cs
- NotifyIcon.cs
- ObjectDataSourceDisposingEventArgs.cs
- MethodBuilder.cs
- XmlNamedNodeMap.cs
- Int32RectValueSerializer.cs
- ObjectListItemCollection.cs
- GACIdentityPermission.cs
- RedirectionProxy.cs
- InsufficientMemoryException.cs
- FixedElement.cs
- DataSourceHelper.cs
- DataGridViewCellStyle.cs
- _ListenerAsyncResult.cs
- ComponentChangingEvent.cs
- BitmapEffectDrawingContextWalker.cs
- BaseParser.cs
- OleAutBinder.cs
- LiteralLink.cs
- activationcontext.cs
- ListViewUpdateEventArgs.cs
- Bits.cs
- View.cs
- TCPListener.cs
- SiteMapNodeItemEventArgs.cs
- DesignTimeTemplateParser.cs
- _ListenerAsyncResult.cs
- NamedPermissionSet.cs
- SimpleBitVector32.cs
- UICuesEvent.cs
- RenderContext.cs
- AssemblyHash.cs
- InternalCache.cs
- Boolean.cs
- WebResourceAttribute.cs
- MultipartContentParser.cs
- ReachPageContentSerializer.cs
- ManagedFilter.cs
- HtmlInputRadioButton.cs
- WebPartUserCapability.cs
- ThousandthOfEmRealPoints.cs
- ImageEditor.cs
- ProtectedConfigurationSection.cs
- ResourceReferenceKeyNotFoundException.cs
- UiaCoreApi.cs
- ReachFixedPageSerializerAsync.cs
- TagMapInfo.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- FileDetails.cs
- RangeValidator.cs
- CultureSpecificCharacterBufferRange.cs
- ReturnEventArgs.cs
- UserControl.cs
- DocumentReference.cs