Table of Contents

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

T

The 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

paths IEnumerable<string>

The include paths, such as Customer.Address.

Exceptions

ArgumentNullException

paths is 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

IList<string>

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

path Expression

The 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

path is 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

path Expression<Func<T, TProperty>>

The expression navigating from T to the property to check.

Returns

bool

true when the graph includes the path; with Lines.Product, o => o.Lines is included.

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

path Expression<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

TProperty

The type of the property.

Exceptions

InvalidOperationException

path goes 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

path Expression<Func<T, TProperty>>

The expression navigating from T to the property to include.

Returns

Graph<T>

This graph, to chain the calls.

Type Parameters

TProperty

Exceptions

ArgumentNullException

path is 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

instance T

The object to parse.

shouldHaveElement bool

true to leave out the empty collections; by default an empty collection is included.

Returns

Graph<T>

The graph of the instance.

Exceptions

ArgumentNullException

instance is 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

path Expression<Func<T, TProperty>>

The expression navigating from T to the property to remove.

Returns

Graph<T>

A copy of the graph without the paths of the property.

Type Parameters

TProperty

The type of the property.