Show / Hide Table of Contents

Class CodeGenerator

Represents code generator.

Inheritance
object
CodeGenerator
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DotNext.Metaprogramming
Assembly: DotNext.Metaprogramming.dll
Syntax
public static class CodeGenerator

Methods

| Edit this page View Source

Assert(Expression, string?)

Checks for a condition; if the condition is false, displays a message box that shows the call stack.

Declaration
[Conditional("DEBUG")]
public static void Assert(Expression test, string? message = null)
Parameters
Type Name Description
Expression test

The conditional expression to evaluate. If the condition is true, the specified message is not sent and the message box is not displayed.

string message

The message to include into trace.

| Edit this page View Source

Assign(Expression?, FieldInfo, Expression)

Adds instance field assignment.

Declaration
public static void Assign(Expression? instance, FieldInfo instanceField, Expression value)
Parameters
Type Name Description
Expression instance

this argument.

FieldInfo instanceField

Instance field to be assigned.

Expression value

A new value of the field.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Assign(Expression?, PropertyInfo, Expression)

Adds instance property assignment.

Declaration
public static void Assign(Expression? instance, PropertyInfo instanceProperty, Expression value)
Parameters
Type Name Description
Expression instance

this argument.

PropertyInfo instanceProperty

Instance property to be assigned.

Expression value

A new value of the property.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Assign(IndexExpression, Expression)

Adds assignment operation to this scope.

Declaration
public static void Assign(IndexExpression indexer, Expression value)
Parameters
Type Name Description
IndexExpression indexer

The indexer property or array element to modify.

Expression value

The value to be assigned to the member or array element.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Assign(MemberExpression, Expression)

Adds assignment operation to this scope.

Declaration
public static void Assign(MemberExpression member, Expression value)
Parameters
Type Name Description
MemberExpression member

The field or property to modify.

Expression value

The value to be assigned to the member.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Assign(ParameterExpression, Expression)

Adds assignment operation to this scope.

Declaration
public static void Assign(ParameterExpression variable, Expression value)
Parameters
Type Name Description
ParameterExpression variable

The variable to modify.

Expression value

The value to be assigned to the variable.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Assign(FieldInfo, Expression)

Adds static field assignment.

Declaration
public static void Assign(FieldInfo staticField, Expression value)
Parameters
Type Name Description
FieldInfo staticField

Static field to be assigned.

Expression value

A new value of the field.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Assign(PropertyInfo, Expression)

Adds static property assignment.

Declaration
public static void Assign(PropertyInfo staticProperty, Expression value)
Parameters
Type Name Description
PropertyInfo staticProperty

Static property to be assigned.

Expression value

A new value of the property.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Assign(string, Expression)

Adds local variable assignment operation this scope.

Declaration
public static void Assign(string variableName, Expression value)
Parameters
Type Name Description
string variableName

The name of the declared local variable.

Expression value

The value to be assigned to the local variable.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

AsyncLambda(Type[], Type, AsyncLambdaFlags, Action<LambdaContext, ParameterExpression>)

Constructs multi-line async lambda function capturing the current lexical scope.

Declaration
public static LambdaExpression AsyncLambda(Type[] parameters, Type returnType, AsyncLambdaFlags flags, Action<LambdaContext, ParameterExpression> body)
Parameters
Type Name Description
Type[] parameters

The parameters.

Type returnType

The return type. Pass typeof(void) for void return type.

AsyncLambdaFlags flags

A set of flags controlling dynamic construction of asynchronous lambda expression.

Action<LambdaContext, ParameterExpression> body

Lambda function builder.

Returns
Type Description
LambdaExpression

Constructed lambda expression.

See Also
AwaitExpression
AsyncResultExpression
Async methods
| Edit this page View Source

AsyncLambda(Type[], Type, AsyncLambdaFlags, Action<LambdaContext>)

Constructs multi-line async lambda function capturing the current lexical scope.

Declaration
public static LambdaExpression AsyncLambda(Type[] parameters, Type returnType, AsyncLambdaFlags flags, Action<LambdaContext> body)
Parameters
Type Name Description
Type[] parameters

The parameters.

Type returnType

The return type. Pass typeof(void) for void return type.

AsyncLambdaFlags flags

A set of flags controlling dynamic construction of asynchronous lambda expression.

Action<LambdaContext> body

Lambda function builder.

Returns
Type Description
LambdaExpression

Constructed lambda expression.

See Also
AwaitExpression
AsyncResultExpression
Async methods
| Edit this page View Source

AsyncLambda<TDelegate>(Action<LambdaContext, ParameterExpression>)

Constructs multi-line async lambda function capturing the current lexical scope.

Declaration
public static Expression<TDelegate> AsyncLambda<TDelegate>(Action<LambdaContext, ParameterExpression> body) where TDelegate : Delegate
Parameters
Type Name Description
Action<LambdaContext, ParameterExpression> body

Lambda function builder.

Returns
Type Description
Expression<TDelegate>

Constructed lambda expression.

Type Parameters
Name Description
TDelegate

The delegate describing signature of lambda function.

See Also
AwaitExpression
AsyncResultExpression
Async methods
| Edit this page View Source

AsyncLambda<TDelegate>(Action<LambdaContext>)

Constructs multi-line async lambda function capturing the current lexical scope.

Declaration
public static Expression<TDelegate> AsyncLambda<TDelegate>(Action<LambdaContext> body) where TDelegate : Delegate
Parameters
Type Name Description
Action<LambdaContext> body

Lambda function builder.

Returns
Type Description
Expression<TDelegate>

Constructed lambda expression.

Type Parameters
Name Description
TDelegate

The delegate describing signature of lambda function.

See Also
AwaitExpression
AsyncResultExpression
Async methods
| Edit this page View Source

AsyncLambda<TDelegate>(bool, Action<LambdaContext, ParameterExpression>)

Constructs multi-line async lambda function capturing the current lexical scope.

Declaration
public static Expression<TDelegate> AsyncLambda<TDelegate>(bool usePooling, Action<LambdaContext, ParameterExpression> body) where TDelegate : Delegate
Parameters
Type Name Description
bool usePooling

true to use task pooling to avoid memory allocation; otherwise, false.

Action<LambdaContext, ParameterExpression> body

Lambda function builder.

Returns
Type Description
Expression<TDelegate>

Constructed lambda expression.

Type Parameters
Name Description
TDelegate

The delegate describing signature of lambda function.

See Also
AwaitExpression
AsyncResultExpression
Async methods
| Edit this page View Source

AsyncLambda<TDelegate>(bool, Action<LambdaContext>)

Constructs multi-line async lambda function capturing the current lexical scope.

Declaration
public static Expression<TDelegate> AsyncLambda<TDelegate>(bool usePooling, Action<LambdaContext> body) where TDelegate : Delegate
Parameters
Type Name Description
bool usePooling

true to use task pooling to avoid memory allocation; otherwise, false.

Action<LambdaContext> body

Lambda function builder.

Returns
Type Description
Expression<TDelegate>

Constructed lambda expression.

Type Parameters
Name Description
TDelegate

The delegate describing signature of lambda function.

See Also
AwaitExpression
AsyncResultExpression
Async methods
| Edit this page View Source

Await(Expression, bool)

Adds await operator.

Declaration
public static void Await(Expression asyncResult, bool configureAwait = false)
Parameters
Type Name Description
Expression asyncResult

The expression representing asynchronous computing process.

bool configureAwait

true to call ConfigureAwait(bool) with false argument.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

AwaitForEach(Expression, Action<MemberExpression, LoopContext>, Expression?, bool)

Adds await foreach loop statement.

Declaration
public static void AwaitForEach(Expression collection, Action<MemberExpression, LoopContext> body, Expression? cancellationToken = null, bool configureAwait = false)
Parameters
Type Name Description
Expression collection

The expression providing enumerable collection.

Action<MemberExpression, LoopContext> body

Loop body.

Expression cancellationToken

The expression of type CancellationToken.

bool configureAwait

true to call ConfigureAwait(bool) with false argument when awaiting MoveNextAsync() method.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
Async Streams
| Edit this page View Source

AwaitForEach(Expression, Action<MemberExpression>, Expression?, bool)

Adds await foreach loop statement.

Declaration
public static void AwaitForEach(Expression collection, Action<MemberExpression> body, Expression? cancellationToken = null, bool configureAwait = false)
Parameters
Type Name Description
Expression collection

The expression providing enumerable collection.

Action<MemberExpression> body

Loop body.

Expression cancellationToken

The expression of type CancellationToken.

bool configureAwait

true to call ConfigureAwait(bool) with false argument when awaiting MoveNextAsync() method.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
Async Streams
| Edit this page View Source

AwaitUsing(Expression, Action, bool)

Adds await using statement.

Declaration
public static void AwaitUsing(Expression resource, Action body, bool configureAwait = false)
Parameters
Type Name Description
Expression resource

The expression representing disposable resource.

Action body

The body of the statement.

bool configureAwait

true to call ConfigureAwait(bool) with false argument when awaiting DisposeAsync() method.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
Using async disposable
| Edit this page View Source

AwaitUsing(Expression, Action<ParameterExpression>, bool)

Adds await using statement.

Declaration
public static void AwaitUsing(Expression resource, Action<ParameterExpression> body, bool configureAwait = false)
Parameters
Type Name Description
Expression resource

The expression representing disposable resource.

Action<ParameterExpression> body

The body of the statement.

bool configureAwait

true to call ConfigureAwait(bool) with false argument when awaiting DisposeAsync() method.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
Using async disposable
| Edit this page View Source

Break()

Stops execution of the entire loop.

Declaration
public static void Break()
Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Break(LoopContext)

Stops execution the specified loop.

Declaration
public static void Break(LoopContext loop)
Parameters
Type Name Description
LoopContext loop

The loop reference.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Breakpoint()

Installs breakpoint.

Declaration
[Conditional("DEBUG")]
public static void Breakpoint()
Remarks

This method installs breakpoint in DEBUG configuration.

| Edit this page View Source

Call(Expression, MethodInfo, IEnumerable<Expression>)

Adds instance method call statement.

Declaration
public static void Call(Expression instance, MethodInfo method, IEnumerable<Expression> arguments)
Parameters
Type Name Description
Expression instance

this argument.

MethodInfo method

The method to be called.

IEnumerable<Expression> arguments

Method call arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Call(Expression, MethodInfo, params Expression[])

Adds instance method call statement.

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

this argument.

MethodInfo method

The method to be called.

Expression[] arguments

Method call arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Call(Expression, string, params Expression[])

Adds instance method call statement.

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

this argument.

string methodName

The method to be called.

Expression[] arguments

Method call arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

CallStatic(MethodInfo, IEnumerable<Expression>)

Adds static method call statement.

Declaration
public static void CallStatic(MethodInfo method, IEnumerable<Expression> arguments)
Parameters
Type Name Description
MethodInfo method

The method to be called.

IEnumerable<Expression> arguments

Method call arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

CallStatic(MethodInfo, params Expression[])

Adds static method call statement.

Declaration
public static void CallStatic(MethodInfo method, params Expression[] arguments)
Parameters
Type Name Description
MethodInfo method

The method to be called.

Expression[] arguments

Method call arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

CallStatic(Type, string, params Expression[])

Adds static method call.

Declaration
public static void CallStatic(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.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

CallStatic<T>(string, params Expression[])

Constructs static method call.

Declaration
public static void CallStatic<T>(string methodName, params Expression[] arguments)
Parameters
Type Name Description
string methodName

The name of the static method.

Expression[] arguments

The arguments to be passed into static method.

Type Parameters
Name Description
T

The type that declares static method.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Continue()

Restarts execution of the entire loop.

Declaration
public static void Continue()
Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Continue(LoopContext)

Restarts execution of the loop.

Declaration
public static void Continue(LoopContext loop)
Parameters
Type Name Description
LoopContext loop

The loop reference.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

DebugMessage(Expression)

Writes line of the text into attached debugger.

Declaration
[Conditional("DEBUG")]
public static void DebugMessage(Expression value)
Parameters
Type Name Description
Expression value

The value to be written into attached debugger.

| Edit this page View Source

DeclareVariable(string, Expression)

Declares initialized local variable of automatically inferred type.

Declaration
public static ParameterExpression DeclareVariable(string name, Expression init)
Parameters
Type Name Description
string name

The name of the variable.

Expression init

Initialization expression.

Returns
Type Description
ParameterExpression

The expression representing local variable.

Remarks

The equivalent code is var i = expr;.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

DeclareVariable(Type, string)

Declares local variable in the current lexical scope.

Declaration
public static ParameterExpression DeclareVariable(Type variableType, string name)
Parameters
Type Name Description
Type variableType

The type of local variable.

string name

The name of local variable.

Returns
Type Description
ParameterExpression

The expression representing local variable.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

DeclareVariable<T>(string)

Declares local variable in the current lexical scope.

Declaration
public static ParameterExpression DeclareVariable<T>(string name)
Parameters
Type Name Description
string name

The name of local variable.

Returns
Type Description
ParameterExpression

The expression representing local variable.

Type Parameters
Name Description
T

The type of local variable.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

DoWhile(Expression, Action)

Adds do{ } while(condition); loop statement.

Declaration
public static void DoWhile(Expression test, Action body)
Parameters
Type Name Description
Expression test

Loop continuation condition.

Action body

Loop body.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
do-while Statement
| Edit this page View Source

DoWhile(Expression, Action<LoopContext>)

Adds do{ } while(condition); loop statement.

Declaration
public static void DoWhile(Expression test, Action<LoopContext> body)
Parameters
Type Name Description
Expression test

Loop continuation condition.

Action<LoopContext> body

Loop body.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
do-while Statement
| Edit this page View Source

Embed<TDelegate>(Expression<TDelegate>, params Expression[])

Inserts expression tree as a statement.

Declaration
public static void Embed<TDelegate>(Expression<TDelegate> lambda, params Expression[] arguments) where TDelegate : MulticastDelegate
Parameters
Type Name Description
Expression<TDelegate> lambda

The expression to be inserted as statement.

Expression[] arguments

The arguments used to replace lambda parameters.

Type Parameters
Name Description
TDelegate

The type of the delegate describing lambda call site.

| Edit this page View Source

For(Expression, Condition, Action<ParameterExpression>, Action<ParameterExpression, LoopContext>)

Adds for loop statement.

Declaration
public static void For(Expression initializer, ForExpression.LoopBuilder.Condition condition, Action<ParameterExpression> iteration, Action<ParameterExpression, LoopContext> body)
Parameters
Type Name Description
Expression initializer

Loop variable initialization expression.

ForExpression.LoopBuilder.Condition condition

Loop continuation condition.

Action<ParameterExpression> iteration

Iteration statements.

Action<ParameterExpression, LoopContext> body

Loop body.

Remarks

This builder constructs the statement equivalent to for(var i = initializer; condition; iter){ body; }.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
for Statement
| Edit this page View Source

For(Expression, Condition, Action<ParameterExpression>, Action<ParameterExpression>)

Adds for loop statement.

Declaration
public static void For(Expression initializer, ForExpression.LoopBuilder.Condition condition, Action<ParameterExpression> iteration, Action<ParameterExpression> body)
Parameters
Type Name Description
Expression initializer

Loop variable initialization expression.

ForExpression.LoopBuilder.Condition condition

Loop continuation condition.

Action<ParameterExpression> iteration

Iteration statements.

Action<ParameterExpression> body

Loop body.

Remarks

This builder constructs the statement equivalent to for(var i = initializer; condition; iter){ body; }.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
for Statement
| Edit this page View Source

ForEach(Expression, Action<MemberExpression, LoopContext>)

Adds foreach loop statement.

Declaration
public static void ForEach(Expression collection, Action<MemberExpression, LoopContext> body)
Parameters
Type Name Description
Expression collection

The expression providing enumerable collection.

Action<MemberExpression, LoopContext> body

Loop body.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
foreach Statement
| Edit this page View Source

ForEach(Expression, Action<MemberExpression>)

Adds foreach loop statement.

Declaration
public static void ForEach(Expression collection, Action<MemberExpression> body)
Parameters
Type Name Description
Expression collection

The expression providing enumerable collection.

Action<MemberExpression> body

Loop body.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
foreach Statement
| Edit this page View Source

Goto(LabelTarget)

Adds unconditional control transfer statement to this scope.

Declaration
public static void Goto(LabelTarget target)
Parameters
Type Name Description
LabelTarget target

The label reference.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Goto(LabelTarget, Expression?)

Adds unconditional control transfer statement to this scope.

Declaration
public static void Goto(LabelTarget target, Expression? value)
Parameters
Type Name Description
LabelTarget target

The label reference.

Expression value

The value to be associated with the control transfer.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

If(Expression)

Adds if-then-else statement to this scope.

Declaration
public static ConditionalBuilder If(Expression test)
Parameters
Type Name Description
Expression test

Test expression.

Returns
Type Description
ConditionalBuilder

Conditional statement builder.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

IfThen(Expression, Action)

Adds if-then statement to this scope.

Declaration
public static void IfThen(Expression test, Action ifTrue)
Parameters
Type Name Description
Expression test

Test expression.

Action ifTrue

Positive branch builder.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

IfThenElse(Expression, Action, Action)

Adds if-then-else statement to this scope.

Declaration
public static void IfThenElse(Expression test, Action ifTrue, Action ifFalse)
Parameters
Type Name Description
Expression test

Test expression.

Action ifTrue

Positive branch builder.

Action ifFalse

Negative branch builder.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

InPlaceValue<T>(T)

Adds constant as in-place statement.

Declaration
public static void InPlaceValue<T>(T value)
Parameters
Type Name Description
T value

The value to be placed as statement.

Type Parameters
Name Description
T

The type of the constant.

| Edit this page View Source

Invoke(Expression, IEnumerable<Expression>)

Adds invocation statement.

Declaration
public static void Invoke(Expression @delegate, IEnumerable<Expression> arguments)
Parameters
Type Name Description
Expression delegate

The expression providing delegate to be invoked.

IEnumerable<Expression> arguments

Delegate invocation arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Invoke(Expression, params Expression[])

Adds invocation statement.

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

The expression providing delegate to be invoked.

Expression[] arguments

Delegate invocation arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Label()

Declares label in the current scope.

Declaration
public static LabelTarget Label()
Returns
Type Description
LabelTarget

Declared label.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Label(LabelTarget)

Adds label landing site to this scope.

Declaration
public static void Label(LabelTarget target)
Parameters
Type Name Description
LabelTarget target

The label target.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Label(Type, string?)

Declares label of the specified type.

Declaration
public static LabelTarget Label(Type type, string? name = null)
Parameters
Type Name Description
Type type

The type of landing site.

string name

The optional name of the label.

Returns
Type Description
LabelTarget

Declared label.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Label<T>(string?)

Declares label of the specified type.

Declaration
public static LabelTarget Label<T>(string? name = null)
Parameters
Type Name Description
string name

The optional name of the label.

Returns
Type Description
LabelTarget

Declared label.

Type Parameters
Name Description
T

The type of landing site.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Lambda<TDelegate>(Action<LambdaContext, ParameterExpression>)

Constructs multi-line lambda function capturing the current lexical scope.

Declaration
public static Expression<TDelegate> Lambda<TDelegate>(Action<LambdaContext, ParameterExpression> body) where TDelegate : Delegate
Parameters
Type Name Description
Action<LambdaContext, ParameterExpression> body

Lambda function builder.

Returns
Type Description
Expression<TDelegate>

Constructed lambda expression.

Type Parameters
Name Description
TDelegate

The delegate describing signature of lambda function.

| Edit this page View Source

Lambda<TDelegate>(Action<LambdaContext>)

Constructs multi-line lambda function capturing the current lexical scope.

Declaration
public static Expression<TDelegate> Lambda<TDelegate>(Action<LambdaContext> body) where TDelegate : Delegate
Parameters
Type Name Description
Action<LambdaContext> body

Lambda function builder.

Returns
Type Description
Expression<TDelegate>

Constructed lambda expression.

Type Parameters
Name Description
TDelegate

The delegate describing signature of lambda function.

| Edit this page View Source

Lambda<TDelegate>(bool, Action<LambdaContext, ParameterExpression>)

Constructs multi-line lambda function capturing the current lexical scope.

Declaration
public static Expression<TDelegate> Lambda<TDelegate>(bool tailCall, Action<LambdaContext, ParameterExpression> body) where TDelegate : Delegate
Parameters
Type Name Description
bool tailCall

true if the lambda expression will be compiled with the tail call optimization, otherwise false.

Action<LambdaContext, ParameterExpression> body

Lambda function builder.

Returns
Type Description
Expression<TDelegate>

Constructed lambda expression.

Type Parameters
Name Description
TDelegate

The delegate describing signature of lambda function.

| Edit this page View Source

Lambda<TDelegate>(bool, Action<LambdaContext>)

Constructs multi-line lambda function capturing the current lexical scope.

Declaration
public static Expression<TDelegate> Lambda<TDelegate>(bool tailCall, Action<LambdaContext> body) where TDelegate : Delegate
Parameters
Type Name Description
bool tailCall

true if the lambda expression will be compiled with the tail call optimization, otherwise false.

Action<LambdaContext> body

Lambda function builder.

Returns
Type Description
Expression<TDelegate>

Constructed lambda expression.

Type Parameters
Name Description
TDelegate

The delegate describing signature of lambda function.

| Edit this page View Source

Lambda<TDelegate>(bool, Func<LambdaContext, Expression>)

Constructs single-line lambda function capturing the current lexical scope.

Declaration
public static Expression<TDelegate> Lambda<TDelegate>(bool tailCall, Func<LambdaContext, Expression> body) where TDelegate : Delegate
Parameters
Type Name Description
bool tailCall

true if the lambda expression will be compiled with the tail call optimization, otherwise false.

Func<LambdaContext, Expression> body

Lambda function builder.

Returns
Type Description
Expression<TDelegate>

Constructed lambda expression.

Type Parameters
Name Description
TDelegate

The delegate describing signature of lambda function.

| Edit this page View Source

Lambda<TDelegate>(Func<LambdaContext, Expression>)

Constructs single-line lambda function capturing the current lexical scope.

Declaration
public static Expression<TDelegate> Lambda<TDelegate>(Func<LambdaContext, Expression> body) where TDelegate : Delegate
Parameters
Type Name Description
Func<LambdaContext, Expression> body

Lambda function builder.

Returns
Type Description
Expression<TDelegate>

Constructed lambda expression.

Type Parameters
Name Description
TDelegate

The delegate describing signature of lambda function.

| Edit this page View Source

Lock(Expression, Action)

Adds lock statement.

Declaration
public static void Lock(Expression syncRoot, Action body)
Parameters
Type Name Description
Expression syncRoot

The object to be locked during execution of the compound statement.

Action body

Synchronized scope of code.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
lock Statement
| Edit this page View Source

Lock(Expression, Action<ParameterExpression>)

Adds lock statement.

Declaration
public static void Lock(Expression syncRoot, Action<ParameterExpression> body)
Parameters
Type Name Description
Expression syncRoot

The object to be locked during execution of the compound statement.

Action<ParameterExpression> body

Synchronized scope of code.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
lock Statement
| Edit this page View Source

Loop(Action)

Adds generic loop statement.

Declaration
public static void Loop(Action body)
Parameters
Type Name Description
Action body

Loop body.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Loop(Action<LoopContext>)

Adds generic loop statement.

Declaration
public static void Loop(Action<LoopContext> body)
Parameters
Type Name Description
Action<LoopContext> body

Loop body.

Remarks

This loop is equivalent to while(true){ }.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Match(Expression)

Adds pattern match statement.

Declaration
public static MatchBuilder Match(Expression value)
Parameters
Type Name Description
Expression value

The value to be matched with patterns.

Returns
Type Description
MatchBuilder

Pattern matcher.

| Edit this page View Source

Nop()

Adds no-operation instruction to this scope.

Declaration
public static void Nop()
Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

NullCoalescingAssignment(IndexExpression, Expression)

Adds an expression that represents null-coalescing assignment of array element of indexer property.

Declaration
public static void NullCoalescingAssignment(IndexExpression indexer, Expression right)
Parameters
Type Name Description
IndexExpression indexer

The indexer property or array element to be assigned.

Expression right

The value to assign to indexer if it is null.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

ArgumentException

right is not assignable to indexer.

| Edit this page View Source

NullCoalescingAssignment(MemberExpression, Expression)

Adds an expression that represents null-coalescing assignment of property of field.

Declaration
public static void NullCoalescingAssignment(MemberExpression member, Expression right)
Parameters
Type Name Description
MemberExpression member

The member to be assigned.

Expression right

The value to assign to member if it is null.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

ArgumentException

right is not assignable to member.

| Edit this page View Source

NullCoalescingAssignment(ParameterExpression, Expression)

Adds an expression that represents null-coalescing assignment of local variable.

Declaration
public static void NullCoalescingAssignment(ParameterExpression variable, Expression right)
Parameters
Type Name Description
ParameterExpression variable

The variable to be assigned.

Expression right

The value to assigned to variable if it is null.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

ArgumentException

right is not assignable to variable.

| Edit this page View Source

NullSafeCall(Expression, MethodInfo, IEnumerable<Expression>)

Adds instance method call statement which is not invoked if instance is null.

Declaration
public static void NullSafeCall(Expression instance, MethodInfo method, IEnumerable<Expression> arguments)
Parameters
Type Name Description
Expression instance

this argument.

MethodInfo method

The method to be called.

IEnumerable<Expression> arguments

Method call arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

NullSafeCall(Expression, MethodInfo, params Expression[])

Adds instance method call statement which is not invoked if instance is null.

Declaration
public static void NullSafeCall(Expression instance, MethodInfo method, params Expression[] arguments)
Parameters
Type Name Description
Expression instance

this argument.

MethodInfo method

The method to be called.

Expression[] arguments

Method call arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

NullSafeCall(Expression, string, params Expression[])

Adds instance method call statement which is not invoked if instance is null.

Declaration
public static void NullSafeCall(Expression instance, string methodName, params Expression[] arguments)
Parameters
Type Name Description
Expression instance

this argument.

string methodName

The method to be called.

Expression[] arguments

Method call arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

NullSafeInvoke(Expression, IEnumerable<Expression>)

Adds invocation statement which is not invoked if delegate is null.

Declaration
public static void NullSafeInvoke(Expression @delegate, IEnumerable<Expression> arguments)
Parameters
Type Name Description
Expression delegate

The expression providing delegate to be invoked.

IEnumerable<Expression> arguments

Delegate invocation arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

NullSafeInvoke(Expression, params Expression[])

Adds invocation statement which is not invoked if delegate is null.

Declaration
public static void NullSafeInvoke(Expression @delegate, params Expression[] arguments)
Parameters
Type Name Description
Expression delegate

The expression providing delegate to be invoked.

Expression[] arguments

Delegate invocation arguments.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PostDecrementAssign(IndexExpression)

Adds an expression that represents the assignment of given field or property followed by a subsequent decrement by 1 of the original member.

Declaration
public static void PostDecrementAssign(IndexExpression member)
Parameters
Type Name Description
IndexExpression member

The member to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PostDecrementAssign(MemberExpression)

Adds an expression that represents the assignment of given field or property followed by a subsequent decrement by 1 of the original member.

Declaration
public static void PostDecrementAssign(MemberExpression member)
Parameters
Type Name Description
MemberExpression member

The member to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PostDecrementAssign(ParameterExpression)

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

Declaration
public static void PostDecrementAssign(ParameterExpression variable)
Parameters
Type Name Description
ParameterExpression variable

The variable to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PostIncrementAssign(IndexExpression)

Adds an expression that represents the assignment of given field or property followed by a subsequent increment by 1 of the original member.

Declaration
public static void PostIncrementAssign(IndexExpression member)
Parameters
Type Name Description
IndexExpression member

The member to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PostIncrementAssign(MemberExpression)

Adds an expression that represents the assignment of given field or property followed by a subsequent increment by 1 of the original member.

Declaration
public static void PostIncrementAssign(MemberExpression member)
Parameters
Type Name Description
MemberExpression member

The member to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PostIncrementAssign(ParameterExpression)

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

Declaration
public static void PostIncrementAssign(ParameterExpression variable)
Parameters
Type Name Description
ParameterExpression variable

The variable to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PreDecrementAssign(IndexExpression)

Adds an expression that decrements given field or property by 1 and assigns the result back to the member.

Declaration
public static void PreDecrementAssign(IndexExpression member)
Parameters
Type Name Description
IndexExpression member

The member to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PreDecrementAssign(MemberExpression)

Adds an expression that decrements given field or property by 1 and assigns the result back to the member.

Declaration
public static void PreDecrementAssign(MemberExpression member)
Parameters
Type Name Description
MemberExpression member

The member to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PreDecrementAssign(ParameterExpression)

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

Declaration
public static void PreDecrementAssign(ParameterExpression variable)
Parameters
Type Name Description
ParameterExpression variable

The variable to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PreIncrementAssign(IndexExpression)

Adds an expression that increments given field or property by 1 and assigns the result back to the member.

Declaration
public static void PreIncrementAssign(IndexExpression member)
Parameters
Type Name Description
IndexExpression member

The member to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PreIncrementAssign(MemberExpression)

Adds an expression that increments given field or property by 1 and assigns the result back to the member.

Declaration
public static void PreIncrementAssign(MemberExpression member)
Parameters
Type Name Description
MemberExpression member

The member to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

PreIncrementAssign(ParameterExpression)

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

Declaration
public static void PreIncrementAssign(ParameterExpression variable)
Parameters
Type Name Description
ParameterExpression variable

The variable to be modified.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Rethrow()

Adds re-throw statement.

Declaration
public static void Rethrow()
Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of catch clause.

| Edit this page View Source

Return(Expression?)

Adds return instruction to return from underlying lambda function having non-void return type.

Declaration
public static void Return(Expression? result = null)
Parameters
Type Name Description
Expression result

Optional value to be returned from the lambda function.

Exceptions
Type Condition
InvalidOperationException

This method is not called from within body of lambda function.

| Edit this page View Source

Statement(Expression)

Adds free-form expression as a statement to the current lexical scope.

Declaration
public static void Statement(Expression expr)
Parameters
Type Name Description
Expression expr

The expression to add.

| Edit this page View Source

Switch(Expression)

Adds selection expression.

Declaration
public static SwitchBuilder Switch(Expression value)
Parameters
Type Name Description
Expression value

The value to be handled by the selection expression.

Returns
Type Description
SwitchBuilder

A new instance of selection expression builder.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
switch Statement
| Edit this page View Source

Throw(Expression)

Adds throw statement to the compound statement.

Declaration
public static void Throw(Expression exception)
Parameters
Type Name Description
Expression exception

The exception to be thrown.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Throw<TException>()

Adds throw statement to the compound statement.

Declaration
public static void Throw<TException>() where TException : Exception, new()
Type Parameters
Name Description
TException

The exception to be thrown.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

| Edit this page View Source

Try(Action)

Adds structured exception handling statement.

Declaration
public static TryBuilder Try(Action scope)
Parameters
Type Name Description
Action scope

try block builder.

Returns
Type Description
TryBuilder

Structured exception handling builder.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
try-catch-finally Statement
| Edit this page View Source

Try(Expression)

Adds structured exception handling statement.

Declaration
public static TryBuilder Try(Expression body)
Parameters
Type Name Description
Expression body

try block.

Returns
Type Description
TryBuilder

Structured exception handling builder.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
try-catch-finally Statement
| Edit this page View Source

Using(Expression, Action)

Adds using statement.

Declaration
public static void Using(Expression resource, Action body)
Parameters
Type Name Description
Expression resource

The expression representing disposable resource.

Action body

The body of the statement.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
using Statement
| Edit this page View Source

Using(Expression, Action<ParameterExpression>)

Adds using statement.

Declaration
public static void Using(Expression resource, Action<ParameterExpression> body)
Parameters
Type Name Description
Expression resource

The expression representing disposable resource.

Action<ParameterExpression> body

The body of the statement.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
using Statement
| Edit this page View Source

Variable(string)

Obtains local variable declared in the current or outer lexical scope.

Declaration
public static ParameterExpression Variable(string name)
Parameters
Type Name Description
string name

The name of the local variable.

Returns
Type Description
ParameterExpression

Declared local variable; or null, if there is no declared local variable with the given name.

| Edit this page View Source

While(Expression, Action)

Adds while loop statement.

Declaration
public static void While(Expression test, Action body)
Parameters
Type Name Description
Expression test

Loop continuation condition.

Action body

Loop body.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
while Statement
| Edit this page View Source

While(Expression, Action<LoopContext>)

Adds while loop statement.

Declaration
public static void While(Expression test, Action<LoopContext> body)
Parameters
Type Name Description
Expression test

Loop continuation condition.

Action<LoopContext> body

Loop body.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
while Statement
| Edit this page View Source

With(Expression, Action<ParameterExpression>)

Adds compound statement hat repeatedly refer to a single object or structure so that the statements can use a simplified syntax when accessing members of the object or structure.

Declaration
public static void With(Expression expression, Action<ParameterExpression> body)
Parameters
Type Name Description
Expression expression

The implicitly referenced object.

Action<ParameterExpression> body

The statement body.

Exceptions
Type Condition
InvalidOperationException

Attempts to call this method out of lexical scope.

See Also
With..End Statement
| Edit this page View Source

WriteError(Expression)

Writes line of the text into Error.

Declaration
public static void WriteError(Expression value)
Parameters
Type Name Description
Expression value

The value to be written into stderr.

| Edit this page View Source

WriteLine(Expression)

Writes line of the text into Out.

Declaration
public static void WriteLine(Expression value)
Parameters
Type Name Description
Expression value

The value to be written into stdout.

  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾