Twig<T>

References
public abstract class Twig<T> : ITwig
Type constrained re-implemention of ITwig.
TType of data in twig.

Properties

CommonMetaData

#
public abstract MetaData CommonMetaData { get; }
Gets the common meta data in this twig. This means the meta data shared amongst all non-null items. Any conflicting meta data (i.e. identical name, different values) will be omitted from this result.
CommonMetaData

Constraint

#
public Type Constraint { get; }
Gets the type constraint for this twig. Since each ITwig instance is some form of Twig<T>, this property tells you what T is.
Constraint

Flavour

#
public TypeFlavour Flavour { get; }
Gets the type flavour of the T constraint.
Flavour
Explicit

ITwig.Items

#
Items
Explicit

ITwig.NonNullItems

#
IEnumerable<object> ITwig.NonNullItems
NonNullItems
Explicit

ITwig.NonNullPears

#
IEnumerable<IPear> ITwig.NonNullPears
NonNullPears
Explicit

ITwig.Pears

#
Pears

ItemCount

#
public abstract int ItemCount { get; }
Gets the number of items in this twig that aren't considered null.
ItemCount

Items

#
public IEnumerable<T> Items { get; }
Get an enumerator for all items in this twig.

LeafCount

#
public abstract int LeafCount { get; }
Gets the number of items in this twig, including nulls.
LeafCount

MetaCount

#
public abstract int MetaCount { get; }
Gets the number of defined meta data palettes in this twig.
MetaCount

NonNullItems

#
public IEnumerable<T> NonNullItems { get; }
Get an enumerator for all non-null items in this twig.

NonNullPears

#
public IEnumerable<Pear<T>> NonNullPears { get; }
Enumerate over all non-null item/meta data tuples.

NullCount

#
public abstract int NullCount { get; }
Gets the number of items in this twig that are nulls. Note: even when a twig contains ValueTypes, it may still have nulls.
NullCount

Pears

#
public IEnumerable<Pear<T>> Pears { get; }
Enumerate over all item/meta data tuples.

TightConstraint

#
public abstract Type TightConstraint { get; }
Gets the type which is common to all values stored in this twig. This is potentially quite an expensive property to call and its value is not cached internally. If the twig contains no values at all, the return value is somewhat undefined but will either be object or ITwig.Constraint.
TightConstraint

Indexers

Explicit

ITwig.this[]

#
IPear ITwig.this[int index]
index (int)
this[]

this[]

#
public abstract Pear<T> this[int index] { get; }
Gets the item/data pear at the given index.
index (int)Index of object.
Pear at index.

Methods

Add

#
public Twig<T> Add(Pear<T> pear)
Add an item/data pear to this twig.
pear (Pear<T>)Pear to add.

Add

#
public Twig<T> Add(T item, MetaData data)
Add an item with meta data to this twig.
item (T)Item to add.
data (MetaData)Associated meta data

Add

#
public Twig<T> Add(T item)
Add an item to this twig.
item (T)Item to add.

AddNull

#
public Twig<T> AddNull()
Add a null item to this twig.

AddRange

#
public Twig<T> AddRange(IEnumerable<Pear<T>> pears)
Add a collection of item/data pears to this twig. This is the fastest AddRange method, especially if the pears argument is in fact an array of pears.
pears (IEnumerable<Pear<T>>)Pears to add.

AddRange

#
public Twig<T> AddRange(IEnumerable<T> items, IEnumerable<MetaData> metaData)
Add a collection of items and data to this twig.
items (IEnumerable<T>)Items to add.
metaData (IEnumerable<MetaData>)Data to add.

AddRange

#
public Twig<T> AddRange(IEnumerable<T> items)
Add a collection of items to this twig.
items (IEnumerable<T>)Items to add.

AddRange

#
public Twig<T> AddRange(Twig<T> twig)
Append another twig to this one.
twig (Twig<T>)Items to add.

Apply

#
public Twig<T> Apply(Expression expression, Resolver resolver, out IExpressionReport report)
Apply an expression to all non-null elements in this twig. For an expression to be successful it needs to not throw exceptions and have a return type that is compatible with the underlying type of this twig.
expression (Expression)Expression to apply.
resolver (Resolver)Variable resolver to use.
report (out IExpressionReport)Report on all expression evaluation issues.

Apply

#
public Twig<T> Apply(Func<T, T> method, Func<T> nullMethod, CancellationToken token)
Create a new twig by applying a delegate to all values.
method (Func<T, T>)Modifier delegate.
nullMethod (Func<T>)Modifier for null values. If not specified, null items will be copied verbatim.
token (CancellationToken)Cancellation token.
Twig with modified values.

Cast

#
public ITwig Cast(Type type)
Cast this twig to a Twig<T> type. This will only work if all non-null items are of the given type.
type (Type)Type.
Twig<T> of the specified type.
Cast

Cast<TQ>

#
public abstract Twig<TQ> Cast<TQ>()
Cast this twig to a Twig<T> type. This will only work if all non-null items are of type TQ.
Twig<T> of type TQ.
Cast

ClearMetaData

#
public virtual Twig<T> ClearMetaData()
Create a new twig with the same items but with no meta data.

Convert<TQ>

#
public Twig<TQ> Convert<TQ>(ConversionDelegate<T, TQ> converter, CancellationToken token, ConversionRecord record)
Convert this twig into another twig of a different type.
converter (ConversionDelegate<T, TQ>)Converter.
token (CancellationToken)Cancellation token.
record (ConversionRecord)If not null, conversion messages will be added to this record.
Twig with converted data.

Convert<TQ>

#
public Twig<TQ> Convert<TQ>(ConversionDelegate<T, TQ> converter, CancellationToken token)
Convert this twig into another twig of a different type.
converter (ConversionDelegate<T, TQ>)Converter.
token (CancellationToken)Cancellation token.
Twig with converted data.

Convert<TQ>

#
public virtual Twig<TQ> Convert<TQ>(Func<T, TQ> conversion, CancellationToken token)
Convert this twig by applying a function to all non-null items.
conversion (Func<T, TQ>)Conversion function.
token (CancellationToken)Cancellation token.
Tree with new items but the same metadata.

CountItems

#
public int CountItems(Predicate<T> predicate)
Count how many items pass a predicate method. Null items are not tested and do not contribute towards the test.
predicate (Predicate<T>)Predicate delegate.
Number of non-null items that pass the predicate.

CountPears

#
public int CountPears(Predicate<Pear<T>> predicate)
Count how many item/data pears pass a predicate method. Null items will be included as pears.NullAt = true;
predicate (Predicate<Pear<T>>)Predicate delegate.
Number of non-null pears that pass the predicate.

Expand

#
public Twig<T> Expand(int targetCount, ExpandMethod method)
Expand this twig until the count is equal to the target count. This functionality is the basis for LongestList matching.
targetCount (int)Count to expand to.
method (ExpandMethod)Item insertion method.
True if twig was modified in any way.

Format

#
public void Format(TwigFormatStyle style, Func<Pear<T>, string> formatDelegate, StringBuilder builder)
Format this twig.
style (TwigFormatStyle)Formatting style.
formatDelegate (Func<Pear<T>, string>)Delegate to use for formatting specific items.
builder (StringBuilder)String builder to append to.
A formatted string representing this twig.

Format

#
public void Format(TwigFormatStyle style, Func<T, string> formatDelegate, StringBuilder builder)
Format this twig.
style (TwigFormatStyle)Formatting style.
formatDelegate (Func<T, string>)Delegate to use for formatting specific items.
builder (StringBuilder)String builder to append to.
A formatted string representing this twig.

Format

#
public void Format(TwigFormatStyle style, StringBuilder builder)
Format this twig.
style (TwigFormatStyle)Formatting style.
builder (StringBuilder)String builder to append to.
A formatted string representing this twig.

Format

#
public void Format(TwigFormatting formatting, Func<Pear<T>, string> formatDelegate, StringBuilder builder)
Format the items and/or data in this twig.
formatting (TwigFormatting)Formatting settings.
formatDelegate (Func<Pear<T>, string>)Delegate to use for formatting specific items.
builder (StringBuilder)String builder to append to.
A formatted string representing this twig.

Format

#
public void Format(TwigFormatting formatting, Func<T, string> formatDelegate, StringBuilder builder)
Format the items and/or data in this twig.
formatting (TwigFormatting)Formatting settings.
formatDelegate (Func<T, string>)Delegate to use for formatting specific items.
builder (StringBuilder)String builder to append to.
A formatted string representing this twig.
Explicit

ITwig.Apply

#
ITwig ITwig.Apply(Expression expression, Resolver resolver, out IExpressionReport report)
expression (Expression)
resolver (Resolver)
report (out IExpressionReport)
Apply
Explicit

ITwig.ClearMetaData

#
ITwig ITwig.ClearMetaData()
ClearMetaData
Explicit

ITwig.Expand

#
ITwig ITwig.Expand(int targetCount, ExpandMethod method)
targetCount (int)
method (ExpandMethod)
Expand
Explicit

ITwig.Format

#
void ITwig.Format(TwigFormatStyle style, StringBuilder builder)
style (TwigFormatStyle)
builder (StringBuilder)
Format
Explicit

ITwig.Format

#
void ITwig.Format(TwigFormatting formatting, StringBuilder builder)
formatting (TwigFormatting)
builder (StringBuilder)
Format
Explicit

ITwig.ItemAt

#
object ITwig.ItemAt(int index)
index (int)
ItemAt
Explicit

ITwig.Map

#
map (Maths.IndexMap)
Map
Explicit

ITwig.MergeMetaData

#
ITwig ITwig.MergeMetaData(ITwig sourceTwig, MergeBehaviour mergeBehaviour)
sourceTwig (ITwig)
mergeBehaviour (MergeBehaviour)
MergeMetaData
Explicit

ITwig.MergeMetaData

#
ITwig ITwig.MergeMetaData(MetaData metaData, MergeBehaviour mergeBehaviour)
metaData (MetaData)
mergeBehaviour (MergeBehaviour)
MergeMetaData
Explicit

ITwig.RemoveAll

#
ITwig ITwig.RemoveAll(Predicate<IPear> filter, RemovalMethod method, CancellationToken token)
filter (Predicate<IPear>)
method (RemovalMethod)
token (CancellationToken)
RemoveAll
Explicit

ITwig.RemoveAll

#
ITwig ITwig.RemoveAll(Predicate<object> filter, RemovalMethod method, CancellationToken token)
filter (Predicate<object>)
method (RemovalMethod)
token (CancellationToken)
RemoveAll
Explicit

ITwig.RemoveAt

#
ITwig ITwig.RemoveAt(int index)
index (int)
RemoveAt
Explicit

ITwig.RemoveIndices

#
ITwig ITwig.RemoveIndices(IEnumerable<int> indices)
indices (IEnumerable<int>)
RemoveIndices
Explicit

ITwig.RemoveMetaData

#
ITwig ITwig.RemoveMetaData(params MetaName[] names)
names (params MetaName[])
RemoveMetaData
Explicit

ITwig.RemoveNulls

#
ITwig ITwig.RemoveNulls()
RemoveNulls
Explicit

ITwig.RemovePattern

#
ITwig ITwig.RemovePattern(IEnumerable<bool> pattern, RemovalMethod method)
pattern (IEnumerable<bool>)
method (RemovalMethod)
RemovePattern
Explicit

ITwig.RemoveRange

#
ITwig ITwig.RemoveRange(int index, int length)
index (int)
length (int)
RemoveRange
Explicit

ITwig.Reverse

#
ITwig ITwig.Reverse()
Reverse
Explicit

ITwig.Shrink

#
ITwig ITwig.Shrink(int targetCount, ShrinkMethod method)
targetCount (int)
method (ShrinkMethod)
Shrink
Explicit

ITwig.Sort

#
ITwig ITwig.Sort(double[] keys)
keys (double[])
Sort
Explicit

ITwig.Sort

#
ITwig ITwig.Sort(int[] keys)
keys (int[])
Sort
Explicit

ITwig.Sort

#
ITwig ITwig.Sort(out IndexMap map)
map (out Maths.IndexMap)
Sort
Explicit

ITwig.Sort

#
ITwig ITwig.Sort(string[] keys)
keys (string[])
Sort
Explicit

ITwig.ToPearArray

#
IPear[] ITwig.ToPearArray(ToArrayMethod method)
method (ToArrayMethod)
ToPearArray

Insert

#
public Twig<T> Insert(int index, Pear<T> pear)
Insert an item/data pear into this twig.
index (int)Index to insert at.
pear (Pear<T>)Pear to insert.

Insert

#
public Twig<T> Insert(int index, T item, MetaData data)
Insert an item with data into this twig.
index (int)Index to insert at.
item (T)Item to insert.
data (MetaData)Associated meta data.

Insert

#
public Twig<T> Insert(int index, T item)
Insert an item into this twig.
index (int)Index to insert at.
item (T)Item to add.

InsertNull

#
public Twig<T> InsertNull(int index)
Insert a null item into this twig.
index (int)Index to insert at.

InsertRange

#
public Twig<T> InsertRange(int index, IEnumerable<Pear<T>> pears)
Insert a collection of item/data pears into this twig.
index (int)Index to insert at.
pears (IEnumerable<Pear<T>>)Pears to insert.

InsertRange

#
public Twig<T> InsertRange(int index, IEnumerable<T> items, IEnumerable<MetaData> metaData)
Insert a collection of items and data into this twig.
index (int)Index to insert at.
items (IEnumerable<T>)Items to insert.
metaData (IEnumerable<MetaData>)Data to insert.

InsertRange

#
public Twig<T> InsertRange(int index, IEnumerable<T> items)
Insert a collection of items into this twig.
index (int)Index to insert at.
items (IEnumerable<T>)Items to insert.

InsertRange

#
public Twig<T> InsertRange(int index, Twig<T> twig)
Insert a twig into this one.
index (int)Index to insert at.
twig (Twig<T>)Twig to insert.

ItemAt

#
public abstract T ItemAt(int index)
Gets the item at the given index.
index (int)Index of item to retrieve.

Map

#
public Twig<T> Map(IndexMap map)
Internal sort method based on an index map.
map (Maths.IndexMap)

MergeMetaData

#
public Twig<T> MergeMetaData(ITwig sourceTwig, MergeBehaviour mergeBehaviour)
Merge all meta data from another twig.
sourceTwig (ITwig)Twig with meta data to merge. Must have the same length as this twig.
mergeBehaviour (MergeBehaviour)Merge behaviour for conflicts.
Twig with merged data.

MergeMetaData

#
public virtual Twig<T> MergeMetaData(MetaData metaData, MergeBehaviour mergeBehaviour)
Merge meta data into every item in this twig.
metaData (MetaData)Meta data to merge into every item in this twig.
mergeBehaviour (MergeBehaviour)Merge behaviour for conflicts.
Twig with merged data.

MetaAt

#
public abstract MetaData MetaAt(int index)
Gets the meta data at the given index.
index (int)Index of meta data to retrieve.
Metadata at given index.
MetaAt

NullAt

#
public abstract bool NullAt(int index)
Gets whether the item at the given index is considered to be a null value.
index (int)Index to inspect.
True if item at index is null.
NullAt

RemoveAll

#
public Twig<T> RemoveAll(Predicate<Pear<T>> predicate, RemovalMethod method, CancellationToken token)
Remove all item/data pears that pass a predicate method.
predicate (Predicate<Pear<T>>)Predicate delegate.
method (RemovalMethod)Removal comparison method.
token (CancellationToken)Cancellation token.
Number of items removed.

RemoveAll

#
public Twig<T> RemoveAll(Predicate<T> predicate, RemovalMethod method, CancellationToken token)
Remove all items that pass a predicate method.
predicate (Predicate<T>)Predicate delegate.
method (RemovalMethod)Removal comparison method.
token (CancellationToken)Cancellation token.
Number of items removed.

RemoveAt

#
public Twig<T> RemoveAt(int index)
Remove the item at the given index.
index (int)Index of item to remove.
Modified twig.

RemoveIndices

#
public Twig<T> RemoveIndices(IEnumerable<int> indices)
Remove all indices from this twig.
indices (IEnumerable<int>)Collection of indices to remove.
Modified twig.

RemoveMetaData

#
public abstract Twig<T> RemoveMetaData(params MetaName[] names)
Remove all meta values with the given names from this twig.
names (params MetaName[])Names to remove.
Modified twig or the same twig if the name did not occur.

RemoveNulls

#
public Twig<T> RemoveNulls()
Remove all null items from this twig.
Number of items removed.
Modified twig.

RemovePattern

#
public Twig<T> RemovePattern(IEnumerable<bool> pattern, RemovalMethod method)
Remove all items that are represented by a boolean pattern.
pattern (IEnumerable<bool>)Pattern. If the pattern is shorter than the twig, it will be repeated.
method (RemovalMethod)Removal comparison method.
Number of items removed.
Modified twig.

RemoveRange

#
public Twig<T> RemoveRange(int index, int length)
Remove a range of items.
index (int)Index of first item to remove.
length (int)Number of consecutive items to remove.
Modified twig.

Reverse

#
public Twig<T> Reverse()
Reverse the order of all items in this twig.
Modified twig.

Shrink

#
public Twig<T> Shrink(int targetCount, ShrinkMethod method)
Shrink this twig until the count is equal to the target count. This functionality is the basis for ShortestList matching.
targetCount (int)Count to shrink to.
method (ShrinkMethod)Item removal method.
True if twig was modified in any way.

Sort

#
public Twig<T> Sort(double[] keys)
Sort all items using a key array of doubles.
keys (double[])Key array with length equal to the twig count.
Modified twig.

Sort

#
public Twig<T> Sort(IComparer<Pear<T>> comparer, out IndexMap map)
Sort all items using a custom comparer.
comparer (IComparer<Pear<T>>)
map (out Maths.IndexMap)
Sorted twig.

Sort

#
public Twig<T> Sort(IComparer<T> comparer, out IndexMap map)
Sort all items using a custom comparer.
comparer (IComparer<T>)
map (out Maths.IndexMap)
Sorted twig.

Sort

#
public Twig<T> Sort(int[] keys)
Sort all items using a key array of integers.
keys (int[])Key array with length equal to the twig count.
Modified twig.

Sort

#
public Twig<T> Sort(out IndexMap map)
Sort all items using the default comparer.
map (out Maths.IndexMap)
Modified twig.

Sort

#
public Twig<T> Sort(string[] keys)
Sort all items using a key array of strings.
keys (string[])Key array with length equal to the twig count.
Modified twig.

ToItemArray

#
public T[] ToItemArray(ToArrayMethod method)
Copy the items to an array.
method (ToArrayMethod)
Array of items.

ToItemArrayInternal

#
protected abstract T[] ToItemArrayInternal()
Return a direct reference to the internal item array if it exists.

ToMetaArray

#
public MetaData[] ToMetaArray(ToArrayMethod method)
Copy the meta data (if any) to an array.
method (ToArrayMethod)Array retrieval method.
Array of meta data or null depending on twig state and method.
ToMetaArray

ToMetaArrayInternal

#
protected abstract MetaData[] ToMetaArrayInternal()
Return a direct reference to the internal meta data array if it exists.

ToNullArray

#
public bool[] ToNullArray(ToArrayMethod method)
Copy the null data (if any) to an array. This method may return null if there is no null data.
method (ToArrayMethod)Array retrieval method.
Array of booleans or null depending on twig state and method.
ToNullArray

ToNullArrayInternal

#
protected abstract bool[] ToNullArrayInternal()
Return a direct reference to the internal null flag array if it exists.

ToPearArray

#
public Pear<T>[] ToPearArray(ToArrayMethod method)
Create an array of item/data pears.
method (ToArrayMethod)
Pear array.

TrueForItems

#
public bool TrueForItems(Predicate<T> predicate)
Test whether a specific predicate is true for all items in this twig. Null items are not tested and do not contribute towards the test.
predicate (Predicate<T>)Predicate delegate.
True if all non-null items in this twig pass the predicate.

TrueForPears

#
public bool TrueForPears(Predicate<Pear<T>> predicate)
Test whether a specific predicate is true for all item/data pears in this twig.
predicate (Predicate<Pear<T>>)Predicate delegate.
True if all pears in this twig pass the predicate.

TryConvert<TQ>

#
public Twig<TQ> TryConvert<TQ>(CancellationToken token, ConversionRecord record)
Try and convert this twig into another using the set of centrally registered conversion delegates.
token (CancellationToken)Cancellation token.
record (ConversionRecord)If not null, conversion messages will be added to this record.
Converted twig or null.
TryConvert

TryConvert<TQ>

#
public Twig<TQ> TryConvert<TQ>(CancellationToken token)
Try and convert this twig into another using the set of centrally registered conversion delegates.
token (CancellationToken)Cancellation token.
Converted twig or null.
TryConvert

TypeAt

#
public abstract Type TypeAt(int index)
Gets the type of the item at the given index.
index (int)Item index to retrieve type for.
Type.
TypeAt

TypeName

#
public string TypeName()
Gets the user friendly type name of the twig type constraint.
User friendly type name.
TypeName

TypeName

#
public string TypeName(GrammarNumber number, GrammarArticle article, GrammarCasing casing)
Gets the user friendly type name of the twig type constraint.
number (Prose.GrammarNumber)Grammar number to use.
article (Prose.GrammarArticle)Article to prefix.
casing (Prose.GrammarCasing)Casing.
User friendly type name.
TypeName

ValidateIndex

#
protected void ValidateIndex(int index, int length)
Throw an exception if the index + length range exceed the twig size.
index (int)First index.
length (int)Length of range.

ValidateIndex

#
protected void ValidateIndex(int index)
Throw an exception if the index exceeds the twig size.
index (int)Index to test.

ValidateIndexPlusOne

#
protected void ValidateIndexPlusOne(int index, int length)
Throw an exception if the index + length range exceed the twig size plus one.
index (int)First index.
length (int)Length of range.

ValidateIndexPlusOne

#
protected void ValidateIndexPlusOne(int index)
Throw an exception if the index exceeds the twig size plus one.
index (int)Index to test.