In This Article

CollectionTagger<T> Class

Provides a thread-safe ITagger<T> implementation that maintains a simple collection of tagged ranges.

public abstract class CollectionTagger<T> : TaggerBase<T>, ICollection<TagVersionRange<T>>, IEnumerable<TagVersionRange<T>>, IEnumerable, ICollectionTagger<T>, ITagger<T>, ITaggerBase, IOrderable, IKeyedObject, INotifyCollectionChanged where T : class, ITag
Type Parameters:
T -

The type of tag associated with this tagger.

Inheritance:
Object TaggerBase<T> Object
Derived:
DelimiterHighlightTagger IndicatorTaggerBase<TTag> ParseErrorTagger SearchResultHighlightTagger
Implements:
ICollectionTagger<T> ITagger<T> ITaggerBase IOrderable IKeyedObject

Constructors

CollectionTagger(String, IEnumerable<Ordering>, ICodeDocument, Boolean)

Initializes a new instance of the CollectionTagger class.

protected CollectionTagger(string key, IEnumerable<Ordering> orderings, ICodeDocument document, bool isForLanguage)
Parameter Type Description
key String

The string-based key that identifies the object.

orderings IEnumerable<Ordering>

The collection of Ordering objects, used to determine how this object is positioned relative to other objects.

document ICodeDocument

The document to which this manager is attached.

isForLanguage Boolean

Indicates whether this tagger is for a language.
If true, the tagger is closed when the document's language changes.

Properties

Count

Gets the number of elements contained in the collection.

public int Count { get; }

Property Value

Int32:

The number of elements contained in the collection.

Item[T]

Gets the tag range that points to the specified tag.

[C#] In C#, this property is the indexer for the CollectionTagger class.

public TagVersionRange<T> this[T tag] { get; }
Parameter Type Description
tag T

The tag for which to search.

Property Value

TagVersionRange<T>:

The tag range that points to the specified tag.

Methods

Add(ITextSnapshotLine, T)

Adds a tag range that is associated with a single snapshot line (e.g. a bookmark indicator tag).

public TagVersionRange<T> Add(ITextSnapshotLine snapshotLine, T tag)
Parameter Type Description
snapshotLine ITextSnapshotLine

The target ITextSnapshotLine.

tag T

The ITag to add.

Returns

TagVersionRange<T>:

The TagVersionRange<T> that was created.

Remarks

The generated ITextVersionRange is created with the DeleteWhenZeroLength and LineBased flags.

Add(TagVersionRange<T>)

Adds a tag range to the collection.

public void Add(TagVersionRange<T> tagRange)
Parameter Type Description
tagRange TagVersionRange<T>

The tag range to add to the collection.

Remarks

This is the lowest-level method used for adding a tag range, and gives the most control over snapshot translation options.

Add(TextSnapshotRange, T)

Adds a tag range that is applied to a snapshot text range (e.g. a breakpoint indicator tag).

public TagVersionRange<T> Add(TextSnapshotRange snapshotRange, T tag)
Parameter Type Description
snapshotRange TextSnapshotRange

The target TextSnapshotRange.

tag T

The ITag to add.

Returns

TagVersionRange<T>:

The TagVersionRange<T> that was created.

Remarks

The generated ITextVersionRange is created with the DeleteWhenZeroLength flag.

Clear()

Removes all items from the collection.

public void Clear()

Contains(TagVersionRange<T>)

Determines whether the collection contains a specific value.

public bool Contains(TagVersionRange<T> tagRange)
Parameter Type Description
tagRange TagVersionRange<T>

The object to locate in the collection.

Returns

Boolean:

true if the item is found in the collection; otherwise, false.

CopyTo(TagVersionRange<T>[], Int32)

Copies the entire collection to a compatible one-dimensional Array, starting at the specified index of the target array.

public void CopyTo(TagVersionRange<T>[] array, int arrayIndex)
Parameter Type Description
array TagVersionRange<T>[]

The one-dimensional Array that is the destination of the elements copied from the collection. The Array must have zero-based indexing.

arrayIndex Int32

The zero-based index in array at which copying begins.

CreateBatch()

Creates an IDisposable object such that while the object is not disposed, items can be added to this collection without any change events being fired, thereby allowing batch updates to occur.

public IDisposable CreateBatch()

Returns

IDisposable:

An IDisposable object. Once disposed, the batch is ended.

FindNext(ITextSnapshotLine, ITagSearchOptions<T>)

Finds the next line-based tag (e.g. a bookmark indicator tag), using the specified search options.

public TagVersionRange<T> FindNext(ITextSnapshotLine snapshotLine, ITagSearchOptions<T> options)
Parameter Type Description
snapshotLine ITextSnapshotLine

The ITextSnapshotLine from which to start the search.

options ITagSearchOptions<T>

The optional ITagSearchOptions<T> that specifies search options.

Returns

TagVersionRange<T>:

The TagVersionRange<T> that was found, if any.

FindNext(TextSnapshotOffset, ITagSearchOptions<T>)

Finds the next text range-based tag (e.g. a breakpoint indicator tag), using the specified search options.

public TagVersionRange<T> FindNext(TextSnapshotOffset snapshotOffset, ITagSearchOptions<T> options)
Parameter Type Description
snapshotOffset TextSnapshotOffset

The TextSnapshotOffset from which to start the search.

options ITagSearchOptions<T>

The optional ITagSearchOptions<T> that specifies search options.

Returns

TagVersionRange<T>:

The TagVersionRange<T> that was found, if any.

GetEnumerator()

Retrieves an IEnumerator object for the entire collection.

public IEnumerator<TagVersionRange<T>> GetEnumerator()

Returns

IEnumerator<TagVersionRange<T>>:

An IEnumerator object for the entire collection

Remarks

Enumerators are intended to be used only to read data in the collection. Enumerators cannot be used to modify the underlying collection.

The enumerator does not have exclusive access to the collection.

When an enumerator is instantiated, it takes a snapshot of the current state of the collection. If changes are made to the collection, such as adding, modifying or deleting elements, the snapshot gets out of sync and the enumerator throws an InvalidOperationException. Two enumerators instantiated from the same collection at the same time can have different snapshots of the collection.

GetTags(NormalizedTextSnapshotRangeCollection, Object)

Returns the tag ranges that intersect with the specified normalized snapshot ranges.

public override IEnumerable<TagSnapshotRange<T>> GetTags(NormalizedTextSnapshotRangeCollection snapshotRanges, object parameter)
Parameter Type Description
snapshotRanges NormalizedTextSnapshotRangeCollection

The collection of normalized snapshot ranges.

parameter Object

An optional parameter that provides contextual information about the tag request.

Returns

IEnumerable<TagSnapshotRange<T>>:

The tag ranges that intersect with the specified normalized snapshot ranges.

Remove(T)

Removes a specific tag instance from the collection.

public bool Remove(T tag)
Parameter Type Description
tag T

The ITag to remove from the collection.

Returns

Boolean:

true if the tag was successfully removed from the collection; otherwise, false

Remove(TagVersionRange<T>)

Removes the first occurrence of a specific tag range from the collection.

public bool Remove(TagVersionRange<T> tagRange)
Parameter Type Description
tagRange TagVersionRange<T>

The tag range to remove from the collection.

Returns

Boolean:

true if the tag range was successfully removed from the collection; otherwise, false

RemoveAll(Predicate<TagVersionRange<T>>)

Removes all objects that match the conditions defined by the specified predicate.

public int RemoveAll(Predicate<TagVersionRange<T>> match)
Parameter Type Description
match Predicate<TagVersionRange<T>>

The predicate that defines the conditions for removal.

Returns

Int32:

The number of objects that were removed.

Toggle(ITextSnapshotLine, T)

Toggles whether a tag is associated with a single snapshot line (e.g. a bookmark indicator tag).

public TagVersionRange<T> Toggle(ITextSnapshotLine snapshotLine, T tag)
Parameter Type Description
snapshotLine ITextSnapshotLine

The target ITextSnapshotLine.

tag T

The ITag to add, if no tag is already on the line.

Returns

TagVersionRange<T>:

The TagVersionRange<T> that was created, if a tag was added.

Toggle(TextSnapshotRange, T)

Toggles whether a tag is associated with a snapshot text range (e.g. a breakpoint indicator tag).

public TagVersionRange<T> Toggle(TextSnapshotRange snapshotRange, T tag)
Parameter Type Description
snapshotRange TextSnapshotRange

The target TextSnapshotRange.

tag T

The ITag to add, if no tag is already in the text range.

Returns

TagVersionRange<T>:

The TagVersionRange<T> that was created, if a tag was added.

Events

CollectionChanged

Occurs when the collection is changed.

public event NotifyCollectionChangedEventHandler CollectionChanged

Event Type

NotifyCollectionChangedEventHandler

Inherited Members