Class HierarchyDecoratorExtensions
- Namespace
- Cuemon.Extensions.Runtime
- Assembly
- Cuemon.Extensions.Core.dll
Extension methods for the IHierarchy<T> interface hidden behind the IDecorator<T> interface.
public static class HierarchyDecoratorExtensions
- Inheritance
-
HierarchyDecoratorExtensions
Methods
AncestorsAndSelf<T>(IDecorator<IHierarchy<T>>)
Gets all ancestors (parent, grandparent, etc.) and self of the specified decorator
in the hierarchical structure.
public static IEnumerable<IHierarchy<T>> AncestorsAndSelf<T>(this IDecorator<IHierarchy<T>> decorator)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
Returns
- IEnumerable<IHierarchy<T>>
An IEnumerable<T> sequence equal to ancestors and self of the specified
decorator
.
Type Parameters
T
The type of the instance represented by the specified
decorator
in the hierarchical structure.
Exceptions
- ArgumentNullException
decorator
is null.
DescendantsAndSelf<T>(IDecorator<IHierarchy<T>>)
Gets all descendants (children, grandchildren, etc.) anf self of the current decorator
in the hierarchical structure.
public static IEnumerable<IHierarchy<T>> DescendantsAndSelf<T>(this IDecorator<IHierarchy<T>> decorator)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
Returns
- IEnumerable<IHierarchy<T>>
An IEnumerable<T> sequence equal to the descendants and self of the specified
decorator
.
Type Parameters
T
The type of the instance represented by the specified
decorator
in the hierarchical structure.
Exceptions
- ArgumentNullException
decorator
is null.
Find<T>(IDecorator<IHierarchy<T>>, Func<IHierarchy<T>, Boolean>)
Retrieves all nodes that match the conditions defined by the function delegate match
.
public static IEnumerable<IHierarchy<T>> Find<T>(this IDecorator<IHierarchy<T>> decorator, Func<IHierarchy<T>, bool> match)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
match
Func<IHierarchy<T>, Boolean>The function delegate that defines the conditions of the nodes to search for.
Returns
- IEnumerable<IHierarchy<T>>
An IEnumerable<T> sequence containing all nodes that match the conditions defined by the specified predicate, if found.
Type Parameters
T
The type of the instance that this node represents.
FindFirst<T>(IDecorator<IHierarchy<T>>, Func<IHierarchy<T>, Boolean>)
Returns the first node that match the conditions defined by the function delegate match
, or a default value if no node is found.
public static IHierarchy<T> FindFirst<T>(this IDecorator<IHierarchy<T>> decorator, Func<IHierarchy<T>, bool> match)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
match
Func<IHierarchy<T>, Boolean>The function delegate that defines the conditions of the nodes to search for.
Returns
- IHierarchy<T>
An IHierarchy<T> node that match the conditions defined by the function delegate
match
, or a default value if no node is found.
Type Parameters
T
The type of the instance that this node represents.
FindFirstInstance<T>(IDecorator<IHierarchy<T>>, Func<IHierarchy<T>, Boolean>)
Returns the first node instance that match the conditions defined by the function delegate match
, or a default value if no node is found.
public static T FindFirstInstance<T>(this IDecorator<IHierarchy<T>> decorator, Func<IHierarchy<T>, bool> match)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
match
Func<IHierarchy<T>, Boolean>The function delegate that defines the conditions of the nodes to search for.
Returns
- T
An Instance that match the conditions defined by the function delegate
match
, or a default value if no node is found.
Type Parameters
T
The type of the instance that this node represents.
FindInstance<T>(IDecorator<IHierarchy<T>>, Func<IHierarchy<T>, Boolean>)
Retrieves all node instances that match the conditions defined by the function delegate match
.
public static IEnumerable<T> FindInstance<T>(this IDecorator<IHierarchy<T>> decorator, Func<IHierarchy<T>, bool> match)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
match
Func<IHierarchy<T>, Boolean>The function delegate that defines the conditions of the nodes to search for.
Returns
- IEnumerable<T>
An IEnumerable<T> sequence containing all node instances that match the conditions defined by the specified predicate, if found.
Type Parameters
T
The type of the instance that this node represents.
FindSingle<T>(IDecorator<IHierarchy<T>>, Func<IHierarchy<T>, Boolean>)
Returns the only node that match the conditions defined by the function delegate match
, or a default value if no node is found; this method throws an exception if more than one node is found.
public static IHierarchy<T> FindSingle<T>(this IDecorator<IHierarchy<T>> decorator, Func<IHierarchy<T>, bool> match)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
match
Func<IHierarchy<T>, Boolean>The function delegate that defines the conditions of the nodes to search for.
Returns
- IHierarchy<T>
An IHierarchy<T> node that match the conditions defined by the function delegate
match
, or a default value if no node is found.
Type Parameters
T
The type of the instance that this node represents.
FindSingleInstance<T>(IDecorator<IHierarchy<T>>, Func<IHierarchy<T>, Boolean>)
Returns the only node that match the conditions defined by the function delegate match
, or a default value if no node instance is found; this method throws an exception if more than one node is found.
public static T FindSingleInstance<T>(this IDecorator<IHierarchy<T>> decorator, Func<IHierarchy<T>, bool> match)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
match
Func<IHierarchy<T>, Boolean>The function delegate that defines the conditions of the nodes to search for.
Returns
- T
An Instance node that match the conditions defined by the function delegate
match
, or a default value if no node instance is found.
Type Parameters
T
The type of the instance that this node represents.
FlattenAll<T>(IDecorator<IHierarchy<T>>)
Flattens the entirety of a hierarchical structure representation into an IEnumerable<T> sequence of nodes.
public static IEnumerable<IHierarchy<T>> FlattenAll<T>(this IDecorator<IHierarchy<T>> decorator)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
Returns
- IEnumerable<IHierarchy<T>>
An IEnumerable<T> sequence of IHierarchy<T> all nodes represented by the hierarchical structure.
Type Parameters
T
The type of the instance represented by the specified
decorator
in the hierarchical structure.
Exceptions
- ArgumentNullException
decorator
is null.
NodeAt<T>(IDecorator<IHierarchy<T>>, Int32)
Returns the node at the specified index of a hierarchical structure.
public static IHierarchy<T> NodeAt<T>(this IDecorator<IHierarchy<T>> decorator, int index)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
index
Int32The zero-based index at which a node should be retrieved in the hierarchical structure.
Returns
- IHierarchy<T>
The node at the specified
index
in the hierarchical structure.
Type Parameters
T
The type of the instance represented by the specified
decorator
in the hierarchical structure.
Exceptions
- ArgumentNullException
decorator
is null.- ArgumentOutOfRangeException
index
is less than zero - or -index
exceeded the count of nodes in the hierarchical structure.
Replace<T>(IDecorator<IHierarchy<T>>, Action<IHierarchy<T>, T>)
Replace the instance of the decorator
with a replacer
delegate.
public static void Replace<T>(this IDecorator<IHierarchy<T>> decorator, Action<IHierarchy<T>, T> replacer)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
replacer
Action<IHierarchy<T>, T>The delegate that will replace the wrapped instance of the
decorator
.
Type Parameters
T
The type of the instance that this node represents.
ReplaceAll<T>(IDecorator<IEnumerable<IHierarchy<T>>>, Action<IHierarchy<T>, T>)
Replace all instances of the decorator
with a replacer
delegate.
public static void ReplaceAll<T>(this IDecorator<IEnumerable<IHierarchy<T>>> decorator, Action<IHierarchy<T>, T> replacer)
Parameters
decorator
IDecorator<IEnumerable<IHierarchy<T>>>The IDecorator{IEnumerable{IHierarchy{T}}} to extend.
replacer
Action<IHierarchy<T>, T>The delegate that will replace all wrapped instances of the
decorator
.
Type Parameters
T
The type of the instance that these nodes represents.
Root<T>(IDecorator<IHierarchy<T>>)
Returns the root node of the specified decorator
in the hierarchical structure.
public static IHierarchy<T> Root<T>(this IDecorator<IHierarchy<T>> decorator)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
Returns
- IHierarchy<T>
An IHierarchy<T> node that represents the root of the specified
decorator
.
Type Parameters
T
The type of the instance represented by the specified
decorator
in the hierarchical structure.
Exceptions
- ArgumentNullException
decorator
is null.
SiblingsAndSelf<T>(IDecorator<IHierarchy<T>>)
Gets all siblings and self after the current decorator
in the hierarchical structure.
public static IEnumerable<IHierarchy<T>> SiblingsAndSelf<T>(this IDecorator<IHierarchy<T>> decorator)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
Returns
- IEnumerable<IHierarchy<T>>
An IEnumerable<T> sequence equal to the siblings and self of the specified
decorator
.
Type Parameters
T
The type of the instance represented by the specified
decorator
in the hierarchical structure.
Exceptions
- ArgumentNullException
decorator
is null.
SiblingsAndSelfAt<T>(IDecorator<IHierarchy<T>>, Int32)
Gets all siblings and self after the current decorator
in the hierarchical structure.
public static IEnumerable<IHierarchy<T>> SiblingsAndSelfAt<T>(this IDecorator<IHierarchy<T>> decorator, int depth)
Parameters
decorator
IDecorator<IHierarchy<T>>The IDecorator{IHierarchy{T}} to extend.
depth
Int32The depth in the hierarchical structure from where to locate the siblings and self nodes.
Returns
- IEnumerable<IHierarchy<T>>
An IEnumerable<T> sequence equal to the siblings and self of the specified
decorator
.
Type Parameters
T
The type of the instance represented by the specified
decorator
in the hierarchical structure.
Exceptions
- ArgumentNullException
decorator
is null.- ArgumentOutOfRangeException
depth
is less than zero.
UseCollection(IDecorator<IHierarchy<DataPair>>, Type)
A formatter implementation that resolves a ICollection.
public static ICollection UseCollection(this IDecorator<IHierarchy<DataPair>> decorator, Type valueType)
Parameters
decorator
IDecorator<IHierarchy<DataPair>>The IDecorator{IHierarchy{DataPair}} to extend.
valueType
TypeThe type of the objects in the collection.
Returns
- ICollection
A ICollection of
valueType
from the enclosed IHierarchy{DataPair} of thedecorator
.
Exceptions
- ArgumentNullException
decorator
cannot be null.
UseConvertibleFormatter(IDecorator<IHierarchy<DataPair>>)
A formatter implementation that resolves a IConvertible.
public static IConvertible UseConvertibleFormatter(this IDecorator<IHierarchy<DataPair>> decorator)
Parameters
decorator
IDecorator<IHierarchy<DataPair>>The IDecorator{IHierarchy{DataPair}} to extend.
Returns
- IConvertible
A IConvertible from the enclosed IHierarchy{DataPair} of the
decorator
.
Exceptions
- ArgumentNullException
decorator
cannot be null.
UseDateTimeFormatter(IDecorator<IHierarchy<DataPair>>)
A formatter implementation that resolves a DateTime.
public static DateTime UseDateTimeFormatter(this IDecorator<IHierarchy<DataPair>> decorator)
Parameters
decorator
IDecorator<IHierarchy<DataPair>>The IDecorator{IHierarchy{DataPair}} to extend.
Returns
UseDecimalFormatter(IDecorator<IHierarchy<DataPair>>)
A formatter implementation that resolves a Decimal.
public static decimal UseDecimalFormatter(this IDecorator<IHierarchy<DataPair>> decorator)
Parameters
decorator
IDecorator<IHierarchy<DataPair>>The IDecorator{IHierarchy{DataPair}} to extend.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.
UseDictionary(IDecorator<IHierarchy<DataPair>>, Type[])
A formatter implementation that resolves a IDictionary.
public static IDictionary UseDictionary(this IDecorator<IHierarchy<DataPair>> decorator, Type[] valueTypes)
Parameters
decorator
IDecorator<IHierarchy<DataPair>>The IDecorator{IHierarchy{DataPair}} to extend.
valueTypes
Type[]The value types that forms a KeyValuePair<TKey,TValue>.
Returns
- IDictionary
A IDictionary with KeyValuePair<TKey,TValue> of
valueTypes
from the enclosed IHierarchy{DataPair} of thedecorator
.
Exceptions
- ArgumentNullException
decorator
cannot be null.
UseGuidFormatter(IDecorator<IHierarchy<DataPair>>)
A formatter implementation that resolves a Guid.
public static Guid UseGuidFormatter(this IDecorator<IHierarchy<DataPair>> decorator)
Parameters
decorator
IDecorator<IHierarchy<DataPair>>The IDecorator{IHierarchy{DataPair}} to extend.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.
UseStringFormatter(IDecorator<IHierarchy<DataPair>>)
A formatter implementation that resolves a String.
public static string UseStringFormatter(this IDecorator<IHierarchy<DataPair>> decorator)
Parameters
decorator
IDecorator<IHierarchy<DataPair>>The IDecorator{IHierarchy{DataPair}} to extend.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.
UseUriFormatter(IDecorator<IHierarchy<DataPair>>)
A formatter implementation that resolves a Uri.
public static Uri UseUriFormatter(this IDecorator<IHierarchy<DataPair>> decorator)
Parameters
decorator
IDecorator<IHierarchy<DataPair>>The IDecorator{IHierarchy{DataPair}} to extend.
Returns
Exceptions
- ArgumentNullException
decorator
cannot be null.