Class Graph<T>
- Namespace
- Arc4u
- Assembly
- Arc4u.dll
The include paths of an aggregate of type T: the references and collections to load with it, such as Customer.Address or Lines.Product.
[JsonConverter(typeof(GraphJsonConverterFactory))]
public class Graph<T> where T : class
Type Parameters
TThe aggregate root: a class (or an interface) of the domain model.
- Inheritance
-
Graph<T>
- Inherited Members
Constructors
Graph()
Creates an empty graph.
public Graph()
Graph(IEnumerable<string>)
Creates a graph holding the given include paths, after checking them against the properties of T.
[RequiresUnreferencedCode("The include paths are checked by looking up the properties by name with reflection: trimming can remove them.")]
public Graph(IEnumerable<string> paths)
Parameters
pathsIEnumerable<string>The include paths, such as
Customer.Address.
Exceptions
- ArgumentNullException
pathsis null.- MissingMemberException
A property of a path does not exist, or is not a class or a generic collection of one class.
Properties
Includes
The include paths of the graph. The getter returns a copy; the setter checks the paths like the constructor.
public IList<string> Includes { get; set; }
Property Value
Exceptions
- ArgumentNullException
The value set is null.
- MissingMemberException
A property of a path set does not exist, or is not a class or a generic collection of one class.
Methods
EvaluateExpression(Expression)
Converts an expression into the dotted path of the members it navigates from its parameter. Select and SelectMany go
through a collection; the other operators, such as Where, OrderBy, Take or First, keep the path of their source.
public static string EvaluateExpression(Expression path)
Parameters
pathExpressionThe expression to evaluate.
Returns
- string
The path, for example
.Orders.Lines, or an empty string when the expression does not navigate from its parameter.
Exceptions
- ArgumentNullException
pathis null.- MemberAccessException
The path goes through a string, a value type, or another type that is not a class or a generic collection of one class.
Exist<TProperty>(Expression<Func<T, TProperty>>)
Checks whether the graph includes the path of an expression, or a path below it. Paths are compared by whole property names, with their casing.
public bool Exist<TProperty>(Expression<Func<T, TProperty>> path) where TProperty : class
Parameters
pathExpression<Func<T, TProperty>>The expression navigating from
Tto the property to check.
Returns
Type Parameters
TProperty
GetGraph<TProperty>(Expression<Func<T, TProperty>>)
Returns the paths below a first-level property, as a graph of that property's type. For a collection property, the paths of the returned graph start at the item type.
public Graph<TProperty> GetGraph<TProperty>(Expression<Func<T, TProperty>> path) where TProperty : class
Parameters
pathExpression<Func<T, TProperty>>The expression selecting a property of
T, one level only.
Returns
- Graph<TProperty>
A new graph holding the paths below the property.
Type Parameters
TPropertyThe type of the property.
Exceptions
- InvalidOperationException
pathgoes deeper than one property.
Include<TProperty>(Expression<Func<T, TProperty>>)
Adds the include path of an expression, such as o => o.Customer.Address or o => o.Lines.Select(l => l.Product). A path already in the graph is not added again.
public Graph<T> Include<TProperty>(Expression<Func<T, TProperty>> path) where TProperty : class
Parameters
pathExpression<Func<T, TProperty>>The expression navigating from
Tto the property to include.
Returns
- Graph<T>
This graph, to chain the calls.
Type Parameters
TProperty
Exceptions
- ArgumentNullException
pathis null.- MemberAccessException
The path goes through a property that is not a class or a generic collection of one class.
Parse(T, bool)
Builds the graph of what an instance holds: the paths of its references and collections that are not null. For a collection, the first item is read.
[RequiresUnreferencedCode("Parse reads the properties of the instance with reflection: trimming can remove them.")]
public static Graph<T> Parse(T instance, bool shouldHaveElement = false)
Parameters
instanceTThe object to parse.
shouldHaveElementbooltrue to leave out the empty collections; by default an empty collection is included.
Returns
- Graph<T>
The graph of the instance.
Exceptions
- ArgumentNullException
instanceis null.
RemoveGraph<TProperty>(Expression<Func<T, TProperty>>)
Returns a copy of the graph without a property and the paths below it. This graph does not change.
public Graph<T> RemoveGraph<TProperty>(Expression<Func<T, TProperty>> path) where TProperty : class
Parameters
pathExpression<Func<T, TProperty>>The expression navigating from
Tto the property to remove.
Returns
- Graph<T>
A copy of the graph without the paths of the property.
Type Parameters
TPropertyThe type of the property.