Twig<T>

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

Properties

CommonMetaData

#
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.
public abstract MetaData CommonMetaData { get; }
CommonMetaData

Constraint

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

Flavour

#
Gets the type flavour of the T constraint.
public TypeFlavour Flavour { get; }
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

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

Items

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

LeafCount

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

MetaCount

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

NonNullItems

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

NonNullPears

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

NullCount

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

Pears

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

TightConstraint

#
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.
public abstract Type TightConstraint { get; }
TightConstraint

Indexers

Explicit

ITwig.this[]

#
IPear ITwig.this[
index
]
this[]

this[]

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

Methods

Add

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

Add

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

Add

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

AddNull

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

AddRange

#
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.
public Twig<T> AddRange(
pears
Pears to add.
)

AddRange

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

AddRange

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

AddRange

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

Apply

#
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.
public Twig<T> Apply(
expression,
Expression to apply.
resolver,
Variable resolver to use.
report
Report on all expression evaluation issues.
)

Apply

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

Cast

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

Cast<TQ>

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

ClearMetaData

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

Convert<TQ>

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

Convert<TQ>

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

Convert<TQ>

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

CountItems

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

CountPears

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

Expand

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

Format

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

Format

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

Format

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

Format

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

Format

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

ITwig.Apply

#
ITwig ITwig.Apply(
expression,
resolver,
report
)
Apply
Explicit

ITwig.ClearMetaData

#
ITwig ITwig.ClearMetaData()
ClearMetaData
Explicit

ITwig.Expand

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

ITwig.Format

#
void ITwig.Format()
Format
Explicit

ITwig.Format

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

ITwig.ItemAt

#
object ITwig.ItemAt(
index
)
ItemAt
Explicit

ITwig.Map

#
Map
Explicit

ITwig.MergeMetaData

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

ITwig.MergeMetaData

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

ITwig.RemoveAll

#
ITwig ITwig.RemoveAll()
RemoveAll
Explicit

ITwig.RemoveAll

#
ITwig ITwig.RemoveAll()
RemoveAll
Explicit

ITwig.RemoveAt

#
ITwig ITwig.RemoveAt(
index
)
RemoveAt
Explicit

ITwig.RemoveIndices

#
ITwig ITwig.RemoveIndices(
indices
)
RemoveIndices
Explicit

ITwig.RemoveMetaData

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

ITwig.RemoveNulls

#
ITwig ITwig.RemoveNulls()
RemoveNulls
Explicit

ITwig.RemovePattern

#
ITwig ITwig.RemovePattern()
RemovePattern
Explicit

ITwig.RemoveRange

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

ITwig.Reverse

#
ITwig ITwig.Reverse()
Reverse
Explicit

ITwig.Shrink

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

ITwig.Sort

#
ITwig ITwig.Sort(
keys
)
Sort
Explicit

ITwig.Sort

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

ITwig.Sort

#
ITwig ITwig.Sort(
map
)
Sort
Explicit

ITwig.Sort

#
ITwig ITwig.Sort(
keys
)
Sort
Explicit

ITwig.ToPearArray

#
IPear[] ITwig.ToPearArray()
ToPearArray

Insert

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

Insert

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

Insert

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

InsertNull

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

InsertRange

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

InsertRange

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

InsertRange

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

InsertRange

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

ItemAt

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

Map

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

MergeMetaData

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

MergeMetaData

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

MetaAt

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

NullAt

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

RemoveAll

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

RemoveAll

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

RemoveAt

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

RemoveIndices

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

RemoveMetaData

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

RemoveNulls

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

RemovePattern

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

RemoveRange

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

Reverse

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

Shrink

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

Sort

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

Sort

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

Sort

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

Sort

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

Sort

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

Sort

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

ToItemArray

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

ToItemArrayInternal

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

ToMetaArray

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

ToMetaArrayInternal

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

ToNullArray

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

ToNullArrayInternal

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

ToPearArray

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

TrueForItems

#
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.
public bool TrueForItems(
predicate
Predicate delegate.
)
True if all non-null items in this twig pass the predicate.

TrueForPears

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

TryConvert<TQ>

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

TryConvert<TQ>

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

TypeAt

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

TypeName

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

TypeName

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

ValidateIndex

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

ValidateIndex

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

ValidateIndexPlusOne

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

ValidateIndexPlusOne

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