Table of Contents

Class Condition

Namespace
DynaSharp
Assembly
DynaSharp.dll

A condition that can be kept in a field, assembled at run time and combined with &, | and !: Condition.Of(Attr("status").Eq("open")).

public abstract class Condition : ICondition
Inheritance
Condition
Implements
Inherited Members
Extension Methods

Remarks

When to use it. The conditions that Attr and the generated Attrs make are structs whose type changes with every .And(), .Or() and .Negate(), which is awkward for a field or a condition built in a loop. Of<T>(T) wraps one in this type, whose type stays the same.

Operators. a.Eq(1) & b.Gt(2) does not compile on two structs: &, | and ! need a Condition on one side, and the struct on the other side converts, as in .If(Open & Attr("version").Eq(v)). Instances are immutable, so one can be shared between threads and commands.

Methods

Of<T>(T)

Wraps a condition in a Condition object, so it can be kept in a field, assembled at run time or combined with &, | and !.

public static Condition Of<T>(T condition) where T : ICondition

Parameters

condition T

The struct condition.

Returns

Condition

The condition, in one object.

Type Parameters

T

The type of the condition.

Render(ref ExpressionSink)

Writes the condition as expression text. Attribute names and values go through Path(string) and DynaSharp.Expressions.ExpressionSink.Value<T, TConverter>(T), which turn them into placeholders.

public abstract void Render(ref ExpressionSink sink)

Parameters

sink ExpressionSink

Where the text goes.

Operators

operator &(Condition, Condition)

Makes a condition that holds when both hold.

public static Condition operator &(Condition left, Condition right)

Parameters

left Condition

The first condition.

right Condition

The second condition.

Returns

Condition

The condition.

operator |(Condition, Condition)

Makes a condition that holds when either holds.

public static Condition operator |(Condition left, Condition right)

Parameters

left Condition

The first condition.

right Condition

The second condition.

Returns

Condition

The condition.

operator !(Condition)

Makes a condition that holds when another one does not.

public static Condition operator !(Condition condition)

Parameters

condition Condition

The other condition.

Returns

Condition

The opposite.