Show / Hide Table of Contents

Class ExpressionBuilder

Provides extension methods to simplify construction of complex expressions.

Inheritance
Object
ExpressionBuilder
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: DotNext.Linq.Expressions
Assembly: DotNext.Metaprogramming.dll
Syntax
public static class ExpressionBuilder

Methods

| Improve this Doc View Source

Add(Expression, Expression)

Constructs binary arithmetic addition expression.

Declaration
public static BinaryExpression Add(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a + b.

| Improve this Doc View Source

And(Expression, Expression)

Constructs binary logical AND expression.

Declaration
public static BinaryExpression And(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a & b.

| Improve this Doc View Source

AndAlso(Expression, Expression)

Constructs binary expression that represents a conditional AND operation that evaluates the second operand only if the first operand evaluates to true.

Declaration
public static BinaryExpression AndAlso(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The first operand.

Expression right

The second operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a && b.

| Improve this Doc View Source

ArrayLength(Expression)

Constructs array length expression.

Declaration
public static UnaryExpression ArrayLength(this Expression array)
Parameters
Type Name Description
Expression array

The array expression.

Returns
Type Description
UnaryExpression

Array length expression.

Remarks

The equivalent code is a.LongLength.

| Improve this Doc View Source

AsDynamic(Expression)

Converts expression to its dynamic representation that allows to construct expression trees using native language expressions.

Declaration
public static dynamic AsDynamic(this Expression expression)
Parameters
Type Name Description
Expression expression

The expression to be converted to dynamic expression builder.

Returns
Type Description
Object

The dynamic representation of expression.

| Improve this Doc View Source

AsNullable(Expression)

Converts value type to the expression of Nullable<T> type.

Declaration
public static Expression AsNullable(this Expression expression)
Parameters
Type Name Description
Expression expression

The expression to be converted.

Returns
Type Description
Expression

The nullable expression.

Remarks

If expression is of pointer of reference type then method returns unmodified expression.

| Improve this Doc View Source

AsOptional(Expression)

Creates the expression of type.

Declaration
public static Expression AsOptional(this Expression expression)
Parameters
Type Name Description
Expression expression

The expression to be converted.

Returns
Type Description
Expression

The expression of type.

| Improve this Doc View Source

AsResult(Expression)

Converts compound expression to its safe equivalent that doesn't throw exception and return instead.

Declaration
public static Expression AsResult(this Expression expression)
Parameters
Type Name Description
Expression expression

The compound expression.

Returns
Type Description
Expression

The expression of type .

| Improve this Doc View Source

Assign(IndexExpression, Expression)

Constructs assignment expression.

Declaration
public static BinaryExpression Assign(this IndexExpression left, Expression value)
Parameters
Type Name Description
IndexExpression left

The assignee.

Expression value

The value to be assigned to the left expression.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a.b[i] = c.

| Improve this Doc View Source

Assign(MemberExpression, Expression)

Constructs assignment expression.

Declaration
public static BinaryExpression Assign(this MemberExpression left, Expression value)
Parameters
Type Name Description
MemberExpression left

The assignee.

Expression value

The value to be assigned to the left expression.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a.member = b.

| Improve this Doc View Source

Assign(ParameterExpression, Expression)

Constructs assignment expression.

Declaration
public static BinaryExpression Assign(this ParameterExpression left, Expression value)
Parameters
Type Name Description
ParameterExpression left

The assignee.

Expression value

The value to be assigned to the left expression.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a = b.

| Improve this Doc View Source

AssignDefault(IndexExpression)

Constructs assignment expression.

Declaration
public static BinaryExpression AssignDefault(this IndexExpression left)
Parameters
Type Name Description
IndexExpression left

The assignee.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a.member[i] = default(T).

| Improve this Doc View Source

AssignDefault(MemberExpression)

Constructs assignment expression.

Declaration
public static BinaryExpression AssignDefault(this MemberExpression left)
Parameters
Type Name Description
MemberExpression left

The assignee.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a.member = default(T).

| Improve this Doc View Source

AssignDefault(ParameterExpression)

Constructs assignment expression.

Declaration
public static BinaryExpression AssignDefault(this ParameterExpression left)
Parameters
Type Name Description
ParameterExpression left

The assignee.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a = default(T).

| Improve this Doc View Source

AsString(Expression)

Constructs expression that calls ToString().

Declaration
public static MethodCallExpression AsString(this Expression obj)
Parameters
Type Name Description
Expression obj

The object to be converted into string.

Returns
Type Description
MethodCallExpression

The expression representing ToString() method call.

| Improve this Doc View Source

Await(Expression, Boolean)

Constructs suspension point in the execution of the lambda function until the awaited task completes.

Declaration
public static AwaitExpression Await(this Expression expression, bool configureAwait = false)
Parameters
Type Name Description
Expression expression

The awaitable expression.

Boolean configureAwait

true to call ConfigureAwait(Boolean) with false argument.

Returns
Type Description
AwaitExpression

await expression.

Remarks

The equivalent code is await b.

See Also
Await expression
| Improve this Doc View Source

Break(LabelTarget)

Constructs loop leave statement.

Declaration
public static GotoExpression Break(this LabelTarget label)
Parameters
Type Name Description
LabelTarget label

The label indicating loop exit.

Returns
Type Description
GotoExpression

Break statement.

Remarks

The equivalent code is break.

| Improve this Doc View Source

Break(LabelTarget, Expression)

Constructs loop leave statement.

Declaration
public static GotoExpression Break(this LabelTarget label, Expression value)
Parameters
Type Name Description
LabelTarget label

The label indicating loop exit.

Expression value

The value to be returned from loop.

Returns
Type Description
GotoExpression

Break statement.

| Improve this Doc View Source

Call(Expression, MethodInfo, Expression[])

Constructs instance method call expression.

Declaration
public static MethodCallExpression Call(this Expression instance, MethodInfo method, params Expression[] arguments)
Parameters
Type Name Description
Expression instance

this argument.

MethodInfo method

The method to be called.

Expression[] arguments

The method arguments.

Returns
Type Description
MethodCallExpression

The method call expression.

Remarks

The equivalent code is obj.Method(a, b,...).

| Improve this Doc View Source

Call(Expression, String, Expression[])

Constructs instance method call expression.

Declaration
public static MethodCallExpression Call(this Expression instance, string methodName, params Expression[] arguments)
Parameters
Type Name Description
Expression instance

this argument.

String methodName

The name of the method to be called.

Expression[] arguments

The method arguments.

Returns
Type Description
MethodCallExpression

The method call expression.

Remarks

The equivalent code is obj.Method().

| Improve this Doc View Source

Call(Expression, Type, String, Expression[])

Constructs interface or base class method call expression.

Declaration
public static MethodCallExpression Call(this Expression instance, Type interfaceType, string methodName, params Expression[] arguments)
Parameters
Type Name Description
Expression instance

this argument.

Type interfaceType

The interface or base class.

String methodName

The name of the method in the interface or base class to be called.

Expression[] arguments

The method arguments.

Returns
Type Description
MethodCallExpression

The method call expression.

Remarks

The equivalent code is ((T)obj).Method().

| Improve this Doc View Source

CallStatic(Type, String, Expression[])

Constructs static method call.

Declaration
public static MethodCallExpression CallStatic(this Type type, string methodName, params Expression[] arguments)
Parameters
Type Name Description
Type type

The type that declares static method.

String methodName

The name of the static method.

Expression[] arguments

The arguments to be passed into static method.

Returns
Type Description
MethodCallExpression

An expression representing static method call.

| Improve this Doc View Source

Concat(Expression, Expression[])

Constructs string concatenation expression.

Declaration
public static MethodCallExpression Concat(this Expression first, params Expression[] other)
Parameters
Type Name Description
Expression first

The first string to concatenate.

Expression[] other

Other strings to concatenate.

Returns
Type Description
MethodCallExpression

An expression presenting concatenation.

| Improve this Doc View Source

Condition(Expression, Expression, Expression, Type)

Constructs conditional expression.

Declaration
public static ConditionalExpression Condition(this Expression test, Expression ifTrue = null, Expression ifFalse = null, Type type = null)
Parameters
Type Name Description
Expression test

Test expression.

Expression ifTrue

Positive branch.

Expression ifFalse

Negative branch.

Type type

The type of conditional expression. Default is Void.

Returns
Type Description
ConditionalExpression

Conditional expression.

Remarks

The equivalent code is a ? b : c.

| Improve this Doc View Source

Condition<TResult>(Expression, Expression, Expression)

Constructs conditional expression.

Declaration
public static ConditionalExpression Condition<TResult>(this Expression test, Expression ifTrue, Expression ifFalse)
Parameters
Type Name Description
Expression test

Test expression.

Expression ifTrue

Positive branch.

Expression ifFalse

Negative branch.

Returns
Type Description
ConditionalExpression

Conditional expression.

Type Parameters
Name Description
TResult

The type of conditional expression. Default is Void.

Remarks

The equivalent code is a ? b : c.

| Improve this Doc View Source

Const<T>(T)

Converts arbitrary value into constant expression.

Declaration
public static ConstantExpression Const<T>(this T value)
Parameters
Type Name Description
T value

The constant value.

Returns
Type Description
ConstantExpression

The expression representing constant.

Type Parameters
Name Description
T

The type of constant.

| Improve this Doc View Source

Continue(LabelTarget)

Constructs loop continuation statement.

Declaration
public static GotoExpression Continue(this LabelTarget label)
Parameters
Type Name Description
LabelTarget label

The label indicating loop start.

Returns
Type Description
GotoExpression

Continue statement.

| Improve this Doc View Source

Convert(Expression, Type)

Constructs type conversion expression.

Declaration
public static UnaryExpression Convert(this Expression expression, Type targetType)
Parameters
Type Name Description
Expression expression

The expression to be converted.

Type targetType

The target type.

Returns
Type Description
UnaryExpression

The type conversion expression.

Remarks

The equivalent code is (T)a.

| Improve this Doc View Source

Convert<T>(Expression)

Constructs type conversion expression.

Declaration
public static UnaryExpression Convert<T>(this Expression expression)
Parameters
Type Name Description
Expression expression

The expression to be converted.

Returns
Type Description
UnaryExpression

The type conversion expression.

Type Parameters
Name Description
T

The target type.

Remarks

The equivalent code is (T)a.

| Improve this Doc View Source

Count(Expression)

Constructs expression representing count of items in the collection or string.

Declaration
public static MemberExpression Count(this Expression collection)
Parameters
Type Name Description
Expression collection

The expression representing collection.

Returns
Type Description
MemberExpression

The expression providing access to the appropriate property indicating the number of items in the collection.

Remarks

The input expression must be of type String, StringBuilder, array or any type implementing ICollection<T> or IReadOnlyCollection<T>.

| Improve this Doc View Source

Default(Type)

Constructs type default value supplier.

Declaration
public static DefaultExpression Default(this Type type)
Parameters
Type Name Description
Type type

The target type.

Returns
Type Description
DefaultExpression

The type default value expression.

Remarks

The equivalent code is default(T).

| Improve this Doc View Source

Divide(Expression, Expression)

Constructs binary arithmetic division expression.

Declaration
public static BinaryExpression Divide(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a / b.

| Improve this Doc View Source

ElementAt(Expression, ItemIndexExpression)

Constructs collection or array element access expression.

Declaration
public static CollectionAccessExpression ElementAt(this Expression collection, ItemIndexExpression index)
Parameters
Type Name Description
Expression collection

The collection.

ItemIndexExpression index

The index of the collection or array element.

Returns
Type Description
CollectionAccessExpression

The collection access expression.

Exceptions
Type Condition
ArgumentException

collection doesn't provide implicit support of Index expression.

See Also
Ranges and Indicies
| Improve this Doc View Source

ElementAt(Expression, Expression[])

Constructs array element access expression.

Declaration
public static IndexExpression ElementAt(this Expression array, params Expression[] indexes)
Parameters
Type Name Description
Expression array

The array expression.

Expression[] indexes

Array element indicies.

Returns
Type Description
IndexExpression

Array element access expression.

Remarks

The equivalent code is a.b[i].

| Improve this Doc View Source

Equal(Expression, Expression)

Constructs equality comparison.

Declaration
public static BinaryExpression Equal(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a == b.

| Improve this Doc View Source

Field(Expression, FieldInfo)

Constructs instance field access expression.

Declaration
public static MemberExpression Field(this Expression instance, FieldInfo field)
Parameters
Type Name Description
Expression instance

this argument.

FieldInfo field

Field metadata.

Returns
Type Description
MemberExpression

Field access expression.

Remarks

The equivalent code is a.b.

| Improve this Doc View Source

Field(Expression, String)

Constructs instance field access expression.

Declaration
public static MemberExpression Field(this Expression instance, string fieldName)
Parameters
Type Name Description
Expression instance

this argument.

String fieldName

The name of the instance field.

Returns
Type Description
MemberExpression

Field access expression.

Remarks

The equivalent code is a.b.

| Improve this Doc View Source

Finally(Expression, Expression)

Constructs a try block with a finally block without catch block.

Declaration
public static TryExpression Finally(this Expression try, Expression finally)
Parameters
Type Name Description
Expression try

try block.

Expression finally

finally block.

Returns
Type Description
TryExpression

Try-finally statement.

Remarks

The equivalent code is try { } finally { }.

| Improve this Doc View Source

For(Expression, ForExpression.LoopBuilder.Condition, ForExpression.LoopBuilder.Iteration, ForExpression.LoopBuilder.Statement)

Creates for loop expression.

Declaration
public static ForExpression For(this Expression initialization, ForExpression.LoopBuilder.Condition condition, ForExpression.LoopBuilder.Iteration iteration, ForExpression.LoopBuilder.Statement body)
Parameters
Type Name Description
Expression initialization

Loop variable initialization expression.

ForExpression.LoopBuilder.Condition condition

The condition of loop continuation.

ForExpression.LoopBuilder.Iteration iteration

The loop iteration statement.

ForExpression.LoopBuilder.Statement body

The loop body.

Returns
Type Description
ForExpression

The constructed loop.

| Improve this Doc View Source

ForEach(Expression, ForEachExpression.Statement)

Creates foreach loop expression.

Declaration
public static ForEachExpression ForEach(this Expression collection, ForEachExpression.Statement body)
Parameters
Type Name Description
Expression collection

The collection to iterate through.

ForEachExpression.Statement body

A delegate that is used to construct the body of the loop.

Returns
Type Description
ForEachExpression

The constructed loop.

| Improve this Doc View Source

Fragment<TDelegate>(Expression<TDelegate>, Expression[])

Extracts body of lambda expression.

Declaration
public static Expression Fragment<TDelegate>(Expression<TDelegate> lambda, params Expression[] arguments)

    where TDelegate : MulticastDelegate
Parameters
Type Name Description
Expression<TDelegate> lambda

The lambda expression.

Expression[] arguments

The arguments used to replace lambda parameters.

Returns
Type Description
Expression

The body of lambda expression.

Type Parameters
Name Description
TDelegate

The type of the delegate describing lambda call site.

| Improve this Doc View Source

Goto(LabelTarget)

Constructs unconditional control transfer statement.

Declaration
public static GotoExpression Goto(this LabelTarget label)
Parameters
Type Name Description
LabelTarget label

The declared label.

Returns
Type Description
GotoExpression

Unconditional control transfer statement.

Remarks

The equivalent code is goto label.

| Improve this Doc View Source

Goto(LabelTarget, Expression)

Constructs unconditional control transfer expression.

Declaration
public static GotoExpression Goto(this LabelTarget label, Expression value)
Parameters
Type Name Description
LabelTarget label

The declared label.

Expression value

The value associated with the label.

Returns
Type Description
GotoExpression

Unconditional control transfer expression.

| Improve this Doc View Source

GreaterThan(Expression, Expression)

Constructs "greater than" numeric comparison.

Declaration
public static BinaryExpression GreaterThan(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a > b.

| Improve this Doc View Source

GreaterThanOrEqual(Expression, Expression)

Constructs "greater than or equal" numeric comparison.

Declaration
public static BinaryExpression GreaterThanOrEqual(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a >= b.

| Improve this Doc View Source

IfNotNull(Expression, Func<ParameterExpression, Expression>)

Creates a new safe navigation expression.

Declaration
public static NullSafetyExpression IfNotNull(this Expression target, Func<ParameterExpression, Expression> body)
Parameters
Type Name Description
Expression target

The expression that is guarded by null check.

Func<ParameterExpression, Expression> body

The body to be executed if target is not null.

Returns
Type Description
NullSafetyExpression

The expression representing safe navigation.

| Improve this Doc View Source

Index(Int32, Boolean)

Constructs expression of type Index.

Declaration
public static ItemIndexExpression Index(this int value, bool fromEnd)
Parameters
Type Name Description
Int32 value

The expression representing index value.

Boolean fromEnd

A boolean indicating if the index is from the start (false) or from the end (true) of a collection.

Returns
Type Description
ItemIndexExpression

Index expression.

| Improve this Doc View Source

Index(Expression, Boolean)

Constructs expression of type Index.

Declaration
public static ItemIndexExpression Index(this Expression value, bool fromEnd)
Parameters
Type Name Description
Expression value

The expression representing index value.

Boolean fromEnd

A boolean indicating if the index is from the start (false) or from the end (true) of a collection.

Returns
Type Description
ItemIndexExpression

Index expression.

Exceptions
Type Condition
ArgumentException

Type of value should be Int32, Int16, Byte or SByte.

| Improve this Doc View Source

InstanceOf(Expression, Type)

Constructs type check expression.

Declaration
public static TypeBinaryExpression InstanceOf(this Expression expression, Type type)
Parameters
Type Name Description
Expression expression

The expression to test.

Type type

The target type.

Returns
Type Description
TypeBinaryExpression

The type test expression.

Remarks

The equivalent code is a is T.

| Improve this Doc View Source

InstanceOf<T>(Expression)

Constructs type check expression.

Declaration
public static TypeBinaryExpression InstanceOf<T>(this Expression expression)
Parameters
Type Name Description
Expression expression

The expression to test.

Returns
Type Description
TypeBinaryExpression

The type test expression.

Type Parameters
Name Description
T

The target type.

Remarks

The equivalent code is a is T.

| Improve this Doc View Source

Invoke(Expression, Expression[])

Constructs delegate invocation expression.

Declaration
public static InvocationExpression Invoke(this Expression delegate, params Expression[] arguments)
Parameters
Type Name Description
Expression delegate

The expression representing delegate.

Expression[] arguments

Invocation arguments.

Returns
Type Description
InvocationExpression

Invocation expression.

Remarks

The equivalent code is delegate.Invoke(a, b,...).

| Improve this Doc View Source

IsNotNull(Expression)

Constructs null check.

Declaration
public static Expression IsNotNull(this Expression operand)
Parameters
Type Name Description
Expression operand

The operand.

Returns
Type Description
Expression

null check operation.

Remarks

The equivalent code is !(a is null).

| Improve this Doc View Source

IsNull(Expression)

Constructs null check.

Declaration
public static Expression IsNull(this Expression operand)
Parameters
Type Name Description
Expression operand

The operand.

Returns
Type Description
Expression

null check operation.

Remarks

The equivalent code is a is null.

| Improve this Doc View Source

LandingSite(LabelTarget)

Constructs label landing site.

Declaration
public static LabelExpression LandingSite(this LabelTarget label)
Parameters
Type Name Description
LabelTarget label

The label reference.

Returns
Type Description
LabelExpression

The label landing site.

Remarks

The equivalent code is label:.

| Improve this Doc View Source

LandingSite(LabelTarget, Expression)

Constructs label landing site with the default value.

Declaration
public static LabelExpression LandingSite(this LabelTarget label, Expression default)
Parameters
Type Name Description
LabelTarget label

The label reference.

Expression default

The default value associated with the label.

Returns
Type Description
LabelExpression

The label landing site.

| Improve this Doc View Source

LeftShift(Expression, Expression)

Constructs bitwise left-shift expression.

Declaration
public static BinaryExpression LeftShift(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a << b in Visual Basic.

| Improve this Doc View Source

LessThan(Expression, Expression)

Constructs "less than" numeric comparison.

Declaration
public static BinaryExpression LessThan(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a < b.

| Improve this Doc View Source

LessThanOrEqual(Expression, Expression)

Constructs "less than or equal" numeric comparison.

Declaration
public static BinaryExpression LessThanOrEqual(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a <= b.

| Improve this Doc View Source

Lock(Expression, LockExpression.Statement)

Creates a new synchronized block of code.

Declaration
public static LockExpression Lock(this Expression syncRoot, LockExpression.Statement body)
Parameters
Type Name Description
Expression syncRoot

The monitor object.

LockExpression.Statement body

The delegate used to construct synchronized block of code.

Returns
Type Description
LockExpression

The synchronized block of code.

| Improve this Doc View Source

Loop(Expression)

Constructs loop statement.

Declaration
public static LoopExpression Loop(this Expression body)
Parameters
Type Name Description
Expression body

The loop body.

Returns
Type Description
LoopExpression

Loop statement.

| Improve this Doc View Source

Loop(Expression, LabelTarget)

Constructs loop statement.

Declaration
public static LoopExpression Loop(this Expression body, LabelTarget break)
Parameters
Type Name Description
Expression body

The loop body.

LabelTarget break

Optional loop break label which will installed automatically.

Returns
Type Description
LoopExpression

Loop statement.

| Improve this Doc View Source

Loop(Expression, LabelTarget, LabelTarget)

Constructs loop statement.

Declaration
public static LoopExpression Loop(this Expression body, LabelTarget break, LabelTarget continue)
Parameters
Type Name Description
Expression body

The loop body.

LabelTarget break

Optional loop break label which will installed automatically.

LabelTarget continue

Optional loop continuation which will be installed automatically.

Returns
Type Description
LoopExpression

Loop statement.

| Improve this Doc View Source

Modulo(Expression, Expression)

Constructs arithmetic remainder expression.

Declaration
public static BinaryExpression Modulo(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a % b.

| Improve this Doc View Source

Multiply(Expression, Expression)

Constructs binary arithmetic multiplication expression.

Declaration
public static BinaryExpression Multiply(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a * b.

| Improve this Doc View Source

Negate(Expression)

Constructs negate expression.

Declaration
public static UnaryExpression Negate(this Expression expression)
Parameters
Type Name Description
Expression expression

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is -a.

| Improve this Doc View Source

New(Expression, Expression[])

Constructs type instantiation expression.

Declaration
public static MethodCallExpression New(this Expression type, params Expression[] args)
Parameters
Type Name Description
Expression type

The expression representing the type to be instantiated.

Expression[] args

The list of arguments to be passed into constructor.

Returns
Type Description
MethodCallExpression

Instantiation expression.

Remarks

The equivalent code is new T().

| Improve this Doc View Source

New(Type, Expression[])

Constructs type instantiation expression.

Declaration
public static NewExpression New(this Type type, params Expression[] args)
Parameters
Type Name Description
Type type

The type to be instantiated.

Expression[] args

The list of arguments to be passed into constructor.

Returns
Type Description
NewExpression

Instantiation expression.

Remarks

The equivalent code is new T().

| Improve this Doc View Source

Not(Expression)

Constructs logical NOT expression.

Declaration
public static UnaryExpression Not(this Expression expression)
Parameters
Type Name Description
Expression expression

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is !a.

| Improve this Doc View Source

NotEqual(Expression, Expression)

Constructs inequality comparison.

Declaration
public static BinaryExpression NotEqual(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a != b.

| Improve this Doc View Source

NullCoalescingAssignment(IndexExpression, Expression)

Constructs null-coalescing assignment expression.

Declaration
public static NullCoalescingAssignmentExpression NullCoalescingAssignment(this IndexExpression left, Expression right)
Parameters
Type Name Description
IndexExpression left

The left operand of the assignment.

Expression right

The right operand of the assignment.

Returns
Type Description
NullCoalescingAssignmentExpression

The constructed expression.

Remarks

The equivalent code is left.Member ??= right;.

Exceptions
Type Condition
ArgumentException

right is not assignable to left.

| Improve this Doc View Source

NullCoalescingAssignment(MemberExpression, Expression)

Constructs null-coalescing assignment expression.

Declaration
public static NullCoalescingAssignmentExpression NullCoalescingAssignment(this MemberExpression left, Expression right)
Parameters
Type Name Description
MemberExpression left

The left operand of the assignment.

Expression right

The right operand of the assignment.

Returns
Type Description
NullCoalescingAssignmentExpression

The constructed expression.

Remarks

The equivalent code is left.Member ??= right;.

Exceptions
Type Condition
ArgumentException

right is not assignable to left.

| Improve this Doc View Source

NullCoalescingAssignment(ParameterExpression, Expression)

Constructs null-coalescing assignment expression.

Declaration
public static NullCoalescingAssignmentExpression NullCoalescingAssignment(this ParameterExpression left, Expression right)
Parameters
Type Name Description
ParameterExpression left

The left operand of the assignment.

Expression right

The right operand of the assignment.

Returns
Type Description
NullCoalescingAssignmentExpression

The constructed expression.

Remarks

The equivalent code is left ??= right;.

Exceptions
Type Condition
ArgumentException

right is not assignable to left.

| Improve this Doc View Source

OnesComplement(Expression)

Constructs ones complement.

Declaration
public static UnaryExpression OnesComplement(this Expression expression)
Parameters
Type Name Description
Expression expression

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is ~a.

| Improve this Doc View Source

Or(Expression, Expression)

Constructs binary logical OR expression.

Declaration
public static BinaryExpression Or(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a | b.

| Improve this Doc View Source

OrElse(Expression, Expression)

Constructs binary expression that represents a conditional OR operation that evaluates the second operand only if the first operand evaluates to false.

Declaration
public static BinaryExpression OrElse(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The first operand.

Expression right

The second operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a || b.

| Improve this Doc View Source

PostDecrementAssign(IndexExpression)

Constructs an expression that represents the assignment of given expression followed by a subsequent decrement by 1 of the original expression.

Declaration
public static UnaryExpression PostDecrementAssign(this IndexExpression operand)
Parameters
Type Name Description
IndexExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is a.b[i]--.

| Improve this Doc View Source

PostDecrementAssign(MemberExpression)

Constructs an expression that represents the assignment of given expression followed by a subsequent decrement by 1 of the original expression.

Declaration
public static UnaryExpression PostDecrementAssign(this MemberExpression operand)
Parameters
Type Name Description
MemberExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is a.b--.

| Improve this Doc View Source

PostDecrementAssign(ParameterExpression)

Constructs an expression that represents the assignment of given expression followed by a subsequent decrement by 1 of the original expression.

Declaration
public static UnaryExpression PostDecrementAssign(this ParameterExpression operand)
Parameters
Type Name Description
ParameterExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is i--.

| Improve this Doc View Source

PostIncrementAssign(IndexExpression)

Constructs an expression that represents the assignment of given expression followed by a subsequent increment by 1 of the original expression.

Declaration
public static UnaryExpression PostIncrementAssign(this IndexExpression operand)
Parameters
Type Name Description
IndexExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is a.b[i]++.

| Improve this Doc View Source

PostIncrementAssign(MemberExpression)

Constructs an expression that represents the assignment of given expression followed by a subsequent increment by 1 of the original expression.

Declaration
public static UnaryExpression PostIncrementAssign(this MemberExpression operand)
Parameters
Type Name Description
MemberExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is a.b++.

| Improve this Doc View Source

PostIncrementAssign(ParameterExpression)

Constructs an expression that represents the assignment of given expression followed by a subsequent increment by 1 of the original expression.

Declaration
public static UnaryExpression PostIncrementAssign(this ParameterExpression operand)
Parameters
Type Name Description
ParameterExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is i++.

| Improve this Doc View Source

Power(Expression, Expression)

Constructs raising a number to a power expression.

Declaration
public static BinaryExpression Power(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a ^ b in Visual Basic.

| Improve this Doc View Source

PreDecrementAssign(IndexExpression)

Constructs an expression that decrements given expression by 1 and assigns the result back to the expression.

Declaration
public static UnaryExpression PreDecrementAssign(this IndexExpression operand)
Parameters
Type Name Description
IndexExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is --a.b[i].

| Improve this Doc View Source

PreDecrementAssign(MemberExpression)

Constructs an expression that decrements given expression by 1 and assigns the result back to the expression.

Declaration
public static UnaryExpression PreDecrementAssign(this MemberExpression operand)
Parameters
Type Name Description
MemberExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is --a.b.

| Improve this Doc View Source

PreDecrementAssign(ParameterExpression)

Constructs an expression that decrements given expression by 1 and assigns the result back to the expression.

Declaration
public static UnaryExpression PreDecrementAssign(this ParameterExpression operand)
Parameters
Type Name Description
ParameterExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is --i.

| Improve this Doc View Source

PreIncrementAssign(IndexExpression)

Constructs an expression that increments given expression by 1 and assigns the result back to the expression.

Declaration
public static UnaryExpression PreIncrementAssign(this IndexExpression operand)
Parameters
Type Name Description
IndexExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is ++a.b[i].

| Improve this Doc View Source

PreIncrementAssign(MemberExpression)

Constructs an expression that increments given expression by 1 and assigns the result back to the expression.

Declaration
public static UnaryExpression PreIncrementAssign(this MemberExpression operand)
Parameters
Type Name Description
MemberExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is ++a.b.

| Improve this Doc View Source

PreIncrementAssign(ParameterExpression)

Constructs an expression that increments given expression by 1 and assigns the result back to the expression.

Declaration
public static UnaryExpression PreIncrementAssign(this ParameterExpression operand)
Parameters
Type Name Description
ParameterExpression operand

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is ++i.

| Improve this Doc View Source

Property(Expression, PropertyInfo, Expression[])

Constructs instance property or indexer access expression.

Declaration
public static Expression Property(this Expression instance, PropertyInfo property, params Expression[] indicies)
Parameters
Type Name Description
Expression instance

this argument.

PropertyInfo property

Property metadata.

Expression[] indicies

Indexer indicies.

Returns
Type Description
Expression

Property access expression.

Remarks

The equivalent code is a.b or a.b[i].

| Improve this Doc View Source

Property(Expression, String, Expression[])

Constructs instance property or indexer access expression.

Declaration
public static Expression Property(this Expression instance, string propertyName, params Expression[] indicies)
Parameters
Type Name Description
Expression instance

this argument.

String propertyName

The name of the instance property or indexer.

Expression[] indicies

Indexer indicies.

Returns
Type Description
Expression

Property access expression.

Remarks

The equivalent code is a.b or a.b[i].

| Improve this Doc View Source

Property(Expression, Type, String, Expression[])

Constructs instance property or indexer access expression declared in the given interface or base type.

Declaration
public static Expression Property(this Expression instance, Type interfaceType, string propertyName, params Expression[] indicies)
Parameters
Type Name Description
Expression instance

this argument.

Type interfaceType

The interface or base class declaring property.

String propertyName

The name of the instance property or indexer.

Expression[] indicies

Indexer indicies.

Returns
Type Description
Expression

Property access expression.

Remarks

The equivalent code is a.b or a.b[i].

| Improve this Doc View Source

Quote(Index)

Converts index to equivalent expression.

Declaration
public static ItemIndexExpression Quote(this in Index index)
Parameters
Type Name Description
Index index

The index value.

Returns
Type Description
ItemIndexExpression

Index expression.

| Improve this Doc View Source

Quote(Range)

Converts range to equivalent expression.

Declaration
public static RangeExpression Quote(this in Range range)
Parameters
Type Name Description
Range range

The range to convert.

Returns
Type Description
RangeExpression

The expression representing given range.

| Improve this Doc View Source

RefAnyVal(ParameterExpression, Type)

Creates a new expression that is equal to refanyval IL instruction.

Declaration
public static RefAnyValExpression RefAnyVal(this ParameterExpression typedRef, Type referenceType)
Parameters
Type Name Description
ParameterExpression typedRef

The variable of type TypedReference.

Type referenceType

The type of the managed reference.

Returns
Type Description
RefAnyValExpression

The expression representing statically typed referenced.

| Improve this Doc View Source

RefAnyVal<T>(ParameterExpression)

Creates a new expression that is equal to refanyval IL instruction.

Declaration
public static RefAnyValExpression RefAnyVal<T>(this ParameterExpression typedRef)
Parameters
Type Name Description
ParameterExpression typedRef

The variable of type TypedReference.

Returns
Type Description
RefAnyValExpression

The expression representing statically typed referenced.

Type Parameters
Name Description
T

The type of the managed reference.

| Improve this Doc View Source

Return(LabelTarget)

Constructs return statement.

Declaration
public static GotoExpression Return(this LabelTarget label)
Parameters
Type Name Description
LabelTarget label

The label representing function exit.

Returns
Type Description
GotoExpression

Return statement.

Remarks

The equivalent code is return.

| Improve this Doc View Source

Return(LabelTarget, Expression)

Constructs return statement with given value.

Declaration
public static GotoExpression Return(this LabelTarget label, Expression value)
Parameters
Type Name Description
LabelTarget label

The label representing function exit.

Expression value

The value to be returned from function.

Returns
Type Description
GotoExpression

Return statement.

Remarks

The equivalent code is return a.

| Improve this Doc View Source

RightShift(Expression, Expression)

Constructs bitwise right-shift expression.

Declaration
public static BinaryExpression RightShift(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a >> b in Visual Basic.

| Improve this Doc View Source

Slice(Expression, ItemIndexExpression, ItemIndexExpression)

Constructs slice of collection or array.

Declaration
public static SliceExpression Slice(this Expression collection, ItemIndexExpression start = null, ItemIndexExpression end = null)
Parameters
Type Name Description
Expression collection

The collection or array.

ItemIndexExpression start

The first index of slice, inclusive.

ItemIndexExpression end

The last index of slice, exclusive.

Returns
Type Description
SliceExpression

The slice of collection or array.

| Improve this Doc View Source

Slice(Expression, Expression)

Constructs slice of collection or array.

Declaration
public static SliceExpression Slice(this Expression collection, Expression range)
Parameters
Type Name Description
Expression collection

The collection or array.

Expression range

The range of collection or array.

Returns
Type Description
SliceExpression

The slice of collection or array.

| Improve this Doc View Source

Subtract(Expression, Expression)

Constructs binary arithmetic subtraction expression.

Declaration
public static BinaryExpression Subtract(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a - b.

| Improve this Doc View Source

Throw(Expression, Type)

Constructs throw expression.

Declaration
public static UnaryExpression Throw(this Expression exception, Type type = null)
Parameters
Type Name Description
Expression exception

An exception to be thrown.

Type type

The type of expression. Default is Void.

Returns
Type Description
UnaryExpression

throw expression.

Remarks

The equivalent code is throw e.

| Improve this Doc View Source

To(ItemIndexExpression, ItemIndexExpression)

Constructs range.

Declaration
public static RangeExpression To(this ItemIndexExpression start, ItemIndexExpression end)
Parameters
Type Name Description
ItemIndexExpression start

The inclusive start index of the range.

ItemIndexExpression end

The exclusive end index of the range.

Returns
Type Description
RangeExpression

The range expression.

| Improve this Doc View Source

To(ItemIndexExpression, Index)

Constructs range.

Declaration
public static RangeExpression To(this ItemIndexExpression start, Index end)
Parameters
Type Name Description
ItemIndexExpression start

The inclusive start index of the range.

Index end

The exclusive end index of the range.

Returns
Type Description
RangeExpression

The range expression.

| Improve this Doc View Source

TryConvert(Expression, Type)

Constructs an expression that represents an explicit reference or boxing conversion where null is supplied if the conversion fails.

Declaration
public static UnaryExpression TryConvert(this Expression expression, Type type)
Parameters
Type Name Description
Expression expression

The expression to convert.

Type type

The target type.

Returns
Type Description
UnaryExpression

Type conversion expression.

Remarks

The equivalent code is a as T.

| Improve this Doc View Source

TryConvert<T>(Expression)

Constructs an expression that represents an explicit reference or boxing conversion where null is supplied if the conversion fails.

Declaration
public static UnaryExpression TryConvert<T>(this Expression expression)
Parameters
Type Name Description
Expression expression

The expression to convert.

Returns
Type Description
UnaryExpression

Type conversion expression.

Type Parameters
Name Description
T

The target type.

Remarks

The equivalent code is a as T.

| Improve this Doc View Source

UnaryPlus(Expression)

Constructs unary plus expression.

Declaration
public static UnaryExpression UnaryPlus(this Expression expression)
Parameters
Type Name Description
Expression expression

The operand.

Returns
Type Description
UnaryExpression

Unary expression.

Remarks

The equivalent code is +a.

| Improve this Doc View Source

Unbox(Expression, Type)

Constructs explicit unboxing.

Declaration
public static UnaryExpression Unbox(this Expression expression, Type type)
Parameters
Type Name Description
Expression expression

The operand.

Type type

The target value type.

Returns
Type Description
UnaryExpression

Unboxing expression.

Remarks

The equivalent code is (T)b.

| Improve this Doc View Source

Unbox<T>(Expression)

Constructs explicit unboxing.

Declaration
public static UnaryExpression Unbox<T>(this Expression expression)

    where T : struct
Parameters
Type Name Description
Expression expression

The operand.

Returns
Type Description
UnaryExpression

Unboxing expression.

Type Parameters
Name Description
T

The target value type.

Remarks

The equivalent code is (T)b.

| Improve this Doc View Source

Until(Expression, WhileExpression.Statement)

Creates do{ }while() loop expression.

Declaration
public static WhileExpression Until(this Expression condition, WhileExpression.Statement body)
Parameters
Type Name Description
Expression condition

The loop condition.

WhileExpression.Statement body

The delegate that is used to construct loop body.

Returns
Type Description
WhileExpression

The constructed loop expression.

Remarks

The equivalent code is do { } while(condition).

See Also
do-while Statement
| Improve this Doc View Source

Using(Expression, UsingExpression.Statement)

Creates block of code associated with disposable resource.

Declaration
public static UsingExpression Using(this Expression resource, UsingExpression.Statement body)
Parameters
Type Name Description
Expression resource

The disposable resource.

UsingExpression.Statement body

The delegate used to construct the block of code.

Returns
Type Description
UsingExpression

The constructed expression.

| Improve this Doc View Source

While(Expression, WhileExpression.Statement)

Creates while loop expression.

Declaration
public static WhileExpression While(this Expression condition, WhileExpression.Statement body)
Parameters
Type Name Description
Expression condition

The loop condition.

WhileExpression.Statement body

The delegate that is used to construct loop body.

Returns
Type Description
WhileExpression

The constructed loop expression.

Remarks

The equivalent code is while(condition) { }.

See Also
while Statement
| Improve this Doc View Source

With(Expression, WithExpression.Statement)

Creates a new instance of WithExpression.

Declaration
public static WithExpression With(this Expression obj, WithExpression.Statement body)
Parameters
Type Name Description
Expression obj

The object to be referred inside of the body.

WithExpression.Statement body

The body of the expression.

Returns
Type Description
WithExpression

The constructed expression.

See Also
With..End Statement
| Improve this Doc View Source

Xor(Expression, Expression)

Constructs binary logical exclusive OR expression.

Declaration
public static BinaryExpression Xor(this Expression left, Expression right)
Parameters
Type Name Description
Expression left

The left operand.

Expression right

The right operand.

Returns
Type Description
BinaryExpression

Binary expression.

Remarks

The equivalent code is a ^ b.

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX