Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / System / Windows / Documents / TextElementEnumerator.cs / 1 / TextElementEnumerator.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: IEnumerator for TextRange and TextElement content.
//
//
// History:
// 05/27/2003 : benwest - Created
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using MS.Internal;
using System.Text;
using MS.Utility;
using System.Windows.Controls;
#pragma warning disable 1634, 1691 // suppressing PreSharp warnings
namespace System.Windows.Documents
{
internal class TextElementEnumerator : IEnumerator where TextElementType : TextElement
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
// Creates an enumerator instance.
// Null start/end creates an empty enumerator.
internal TextElementEnumerator(TextPointer start, TextPointer end)
{
Invariant.Assert(start != null && end != null || start == null && end == null, "If start is null end should be null!");
_start = start;
_end = end;
// Remember what generation the backing store was in when we started,
// so we can throw if this enumerator is accessed after content has
// changed.
if (_start != null)
{
_generation = _start.TextContainer.Generation;
}
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
public void Dispose()
{
// Empty the enumerator
_current = null;
_navigator = null;
}
object System.Collections.IEnumerator.Current
{
get
{
return this.Current;
}
}
///
/// Return the current object this enumerator is pointing to. This is
/// generally a FrameworkElement, TextElement, an embedded
/// object, or Text content.
///
///
/// According to the IEnumerator spec, the Current property keeps
/// the element even after the content has been modified
/// (even if the current element has been deleted from the collection).
/// This is unlike to Reset or MoveNext which throw after any content change.
///
public TextElementType Current
{
get
{
if (_navigator == null)
{
#pragma warning suppress 6503 // IEnumerator.Current is documented to throw this exception
throw new InvalidOperationException(SR.Get(SRID.EnumeratorNotStarted));
}
if (_current == null)
{
#pragma warning suppress 6503 // IEnumerator.Current is documented to throw this exception
throw new InvalidOperationException(SR.Get(SRID.EnumeratorReachedEnd));
}
return _current;
}
}
///
/// Advance the enumerator to the next object in the range. Return true if content
/// was found.
///
public bool MoveNext()
{
// Throw if the tree has been modified since this enumerator was created.
if (_start != null && _generation != _start.TextContainer.Generation)
{
throw new InvalidOperationException(SR.Get(SRID.EnumeratorVersionChanged));
}
// Return false if the collection is empty
if (_start == null || _start.CompareTo(_end) == 0)
{
return false;
}
// Return false if the navigator reached the end of the collection
if (_navigator != null && _navigator.CompareTo(_end) >= 0)
{
return false;
}
// Advance the navigator
if (_navigator == null)
{
// Set it to the first element for the very first move
_navigator = new TextPointer(_start);
_navigator.MoveToNextContextPosition(LogicalDirection.Forward);
}
else
{
// Move to the next element in the collection
Invariant.Assert(_navigator.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart,
"Unexpected run type in TextElementEnumerator");
_navigator.MoveToElementEdge(ElementEdge.AfterEnd);
_navigator.MoveToNextContextPosition(LogicalDirection.Forward);
}
// Update current cache
if (_navigator.CompareTo(_end) < 0)
{
_current = (TextElementType)_navigator.Parent;
}
else
{
_current = null;
}
// Return true if the content was found
return (_current != null);
}
///
/// Reset the enumerator to the start of the range.
///
public void Reset()
{
// Throw if the tree has been modified since this enumerator was created.
if (_start != null && _generation != _start.TextContainer.Generation)
{
throw new InvalidOperationException(SR.Get(SRID.EnumeratorVersionChanged));
}
_navigator = null;
_current = null;
}
#endregion Public Methods
//------------------------------------------------------
//
// Public Properties
//
//------------------------------------------------------
#region Public Properties
#endregion Public Properties
//-----------------------------------------------------
//
// Public Events
//
//------------------------------------------------------
#region Public Events
#endregion Public Events
//-----------------------------------------------------
//
// Protected Methods
//
//-----------------------------------------------------
#region Protected Methods
#endregion Protected Events
//-----------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal Methods
#endregion Internal methods
//-----------------------------------------------------
//
// Internal Properties
//
//------------------------------------------------------
#region Internal Properties
#endregion Internal Properties
//------------------------------------------------------
//
// Internal Events
//
//-----------------------------------------------------
#region Internal Events
#endregion Internal Events
//------------------------------------------------------
//
// Private Properties
//
//-----------------------------------------------------
#region Private Properties
#endregion Private Properties
//-----------------------------------------------------
//
// Private Fields
//
//-----------------------------------------------------
#region Private Fields
// Edges of the span to enumerator over.
private readonly TextPointer _start;
private readonly TextPointer _end;
// Backing store generation when this enumerator was created.
private readonly uint _generation;
// Current position in the enumeration.
private TextPointer _navigator;
// Calculated content at the current position.
private TextElementType _current;
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: IEnumerator for TextRange and TextElement content.
//
//
// History:
// 05/27/2003 : benwest - Created
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using MS.Internal;
using System.Text;
using MS.Utility;
using System.Windows.Controls;
#pragma warning disable 1634, 1691 // suppressing PreSharp warnings
namespace System.Windows.Documents
{
internal class TextElementEnumerator : IEnumerator where TextElementType : TextElement
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
// Creates an enumerator instance.
// Null start/end creates an empty enumerator.
internal TextElementEnumerator(TextPointer start, TextPointer end)
{
Invariant.Assert(start != null && end != null || start == null && end == null, "If start is null end should be null!");
_start = start;
_end = end;
// Remember what generation the backing store was in when we started,
// so we can throw if this enumerator is accessed after content has
// changed.
if (_start != null)
{
_generation = _start.TextContainer.Generation;
}
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
public void Dispose()
{
// Empty the enumerator
_current = null;
_navigator = null;
}
object System.Collections.IEnumerator.Current
{
get
{
return this.Current;
}
}
///
/// Return the current object this enumerator is pointing to. This is
/// generally a FrameworkElement, TextElement, an embedded
/// object, or Text content.
///
///
/// According to the IEnumerator spec, the Current property keeps
/// the element even after the content has been modified
/// (even if the current element has been deleted from the collection).
/// This is unlike to Reset or MoveNext which throw after any content change.
///
public TextElementType Current
{
get
{
if (_navigator == null)
{
#pragma warning suppress 6503 // IEnumerator.Current is documented to throw this exception
throw new InvalidOperationException(SR.Get(SRID.EnumeratorNotStarted));
}
if (_current == null)
{
#pragma warning suppress 6503 // IEnumerator.Current is documented to throw this exception
throw new InvalidOperationException(SR.Get(SRID.EnumeratorReachedEnd));
}
return _current;
}
}
///
/// Advance the enumerator to the next object in the range. Return true if content
/// was found.
///
public bool MoveNext()
{
// Throw if the tree has been modified since this enumerator was created.
if (_start != null && _generation != _start.TextContainer.Generation)
{
throw new InvalidOperationException(SR.Get(SRID.EnumeratorVersionChanged));
}
// Return false if the collection is empty
if (_start == null || _start.CompareTo(_end) == 0)
{
return false;
}
// Return false if the navigator reached the end of the collection
if (_navigator != null && _navigator.CompareTo(_end) >= 0)
{
return false;
}
// Advance the navigator
if (_navigator == null)
{
// Set it to the first element for the very first move
_navigator = new TextPointer(_start);
_navigator.MoveToNextContextPosition(LogicalDirection.Forward);
}
else
{
// Move to the next element in the collection
Invariant.Assert(_navigator.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart,
"Unexpected run type in TextElementEnumerator");
_navigator.MoveToElementEdge(ElementEdge.AfterEnd);
_navigator.MoveToNextContextPosition(LogicalDirection.Forward);
}
// Update current cache
if (_navigator.CompareTo(_end) < 0)
{
_current = (TextElementType)_navigator.Parent;
}
else
{
_current = null;
}
// Return true if the content was found
return (_current != null);
}
///
/// Reset the enumerator to the start of the range.
///
public void Reset()
{
// Throw if the tree has been modified since this enumerator was created.
if (_start != null && _generation != _start.TextContainer.Generation)
{
throw new InvalidOperationException(SR.Get(SRID.EnumeratorVersionChanged));
}
_navigator = null;
_current = null;
}
#endregion Public Methods
//------------------------------------------------------
//
// Public Properties
//
//------------------------------------------------------
#region Public Properties
#endregion Public Properties
//-----------------------------------------------------
//
// Public Events
//
//------------------------------------------------------
#region Public Events
#endregion Public Events
//-----------------------------------------------------
//
// Protected Methods
//
//-----------------------------------------------------
#region Protected Methods
#endregion Protected Events
//-----------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal Methods
#endregion Internal methods
//-----------------------------------------------------
//
// Internal Properties
//
//------------------------------------------------------
#region Internal Properties
#endregion Internal Properties
//------------------------------------------------------
//
// Internal Events
//
//-----------------------------------------------------
#region Internal Events
#endregion Internal Events
//------------------------------------------------------
//
// Private Properties
//
//-----------------------------------------------------
#region Private Properties
#endregion Private Properties
//-----------------------------------------------------
//
// Private Fields
//
//-----------------------------------------------------
#region Private Fields
// Edges of the span to enumerator over.
private readonly TextPointer _start;
private readonly TextPointer _end;
// Backing store generation when this enumerator was created.
private readonly uint _generation;
// Current position in the enumeration.
private TextPointer _navigator;
// Calculated content at the current position.
private TextElementType _current;
#endregion Private Fields
}
}
// 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
- _FtpControlStream.cs
- CommandID.cs
- ListItemConverter.cs
- AbstractDataSvcMapFileLoader.cs
- SafeArrayRankMismatchException.cs
- PrivateFontCollection.cs
- DrawTreeNodeEventArgs.cs
- CfgParser.cs
- RegexCode.cs
- CodeTryCatchFinallyStatement.cs
- PropertyToken.cs
- CollectionViewProxy.cs
- followingsibling.cs
- ToolboxItem.cs
- DocumentScope.cs
- WebException.cs
- PageContentAsyncResult.cs
- Profiler.cs
- RIPEMD160Managed.cs
- WebPartDisplayModeCancelEventArgs.cs
- EntityClassGenerator.cs
- SystemIPAddressInformation.cs
- StateWorkerRequest.cs
- RotateTransform.cs
- backend.cs
- XPathSelectionIterator.cs
- DataListItemEventArgs.cs
- TextWriter.cs
- ExpressionBinding.cs
- Accessible.cs
- ChannelCredentials.cs
- RtfToXamlReader.cs
- WebConfigurationHostFileChange.cs
- InternalBase.cs
- DataGridAutoFormatDialog.cs
- DbFunctionCommandTree.cs
- RegexStringValidatorAttribute.cs
- RSATokenProvider.cs
- SqlDataSourceStatusEventArgs.cs
- TextContainerHelper.cs
- ReturnType.cs
- basemetadatamappingvisitor.cs
- OracleMonthSpan.cs
- SharedDp.cs
- BinaryParser.cs
- MouseButton.cs
- MergeLocalizationDirectives.cs
- SecurityTokenException.cs
- RequestCacheEntry.cs
- TextPointerBase.cs
- OuterGlowBitmapEffect.cs
- TypeReference.cs
- NativeMethods.cs
- SuppressMergeCheckAttribute.cs
- Mappings.cs
- ConfigurationPermission.cs
- SqlRecordBuffer.cs
- StringFormat.cs
- SvcMapFileSerializer.cs
- SourceLineInfo.cs
- CDSsyncETWBCLProvider.cs
- XmlQualifiedNameTest.cs
- IdentityNotMappedException.cs
- XmlSchemaAttributeGroup.cs
- NonClientArea.cs
- OperationAbortedException.cs
- SQLInt16Storage.cs
- XmlAttributeOverrides.cs
- BufferModesCollection.cs
- XhtmlBasicCalendarAdapter.cs
- SqlGenericUtil.cs
- NativeMethods.cs
- WindowsUserNameSecurityTokenAuthenticator.cs
- MemberPathMap.cs
- ContentPlaceHolder.cs
- ThicknessKeyFrameCollection.cs
- ToolStripScrollButton.cs
- IntAverageAggregationOperator.cs
- LinkedDataMemberFieldEditor.cs
- TraceUtility.cs
- NavigationWindowAutomationPeer.cs
- CodeDomSerializer.cs
- EntityDesignerBuildProvider.cs
- XmlSchemaSet.cs
- XamlGridLengthSerializer.cs
- XsdValidatingReader.cs
- ByteAnimationUsingKeyFrames.cs
- OrderedDictionary.cs
- Blend.cs
- Confirm.cs
- DataTrigger.cs
- MemberHolder.cs
- SoapProtocolReflector.cs
- ConversionContext.cs
- AccessedThroughPropertyAttribute.cs
- AttributeProviderAttribute.cs
- ComplexPropertyEntry.cs
- TableCellCollection.cs
- RepeaterCommandEventArgs.cs
- TextAutomationPeer.cs