Class CodeGenerator
Represents code generator.
Inherited Members
Namespace: DotNext.Metaprogramming
Assembly: DotNext.Metaprogramming.dll
Syntax
public static class CodeGenerator
Methods
| Edit this page View SourceAssert(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. |
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 |
|
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. |
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 |
|
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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 |
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
| Edit this page View SourceAsyncLambda(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 |
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
| Edit this page View SourceAsyncLambda<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
| Edit this page View SourceAsyncLambda<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
| Edit this page View SourceAsyncLambda<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
| Edit this page View SourceAsyncLambda<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
| Edit this page View SourceAwait(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. |
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
| Edit this page View SourceAwaitForEach(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
| Edit this page View SourceAwaitUsing(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
| Edit this page View SourceAwaitUsing(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
| Edit this page View SourceBreak()
Stops execution of the entire loop.
Declaration
public static void Break()
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Attempts to call this method out of lexical scope. |
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. |
Breakpoint()
Installs breakpoint.
Declaration
[Conditional("DEBUG")]
public static void Breakpoint()
Remarks
This method installs breakpoint in DEBUG configuration.
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 |
|
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. |
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 |
|
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. |
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 |
|
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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
| Edit this page View SourceDoWhile(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
| Edit this page View SourceEmbed<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. |
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
| Edit this page View SourceFor(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
| Edit this page View SourceForEach(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
| Edit this page View SourceForEach(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
| Edit this page View SourceGoto(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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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
| Edit this page View SourceLock(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
| Edit this page View SourceLoop(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. |
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. |
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. |
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. |
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 |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Attempts to call this method out of lexical scope. |
ArgumentException |
|
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 |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Attempts to call this method out of lexical scope. |
ArgumentException |
|
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 |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Attempts to call this method out of lexical scope. |
ArgumentException |
|
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 |
|
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. |
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 |
|
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. |
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 |
|
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
Rethrow()
Adds re-throw statement.
Declaration
public static void Rethrow()
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Attempts to call this method out of catch clause. |
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. |
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. |
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
| Edit this page View SourceThrow(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. |
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. |
Try(Action)
Adds structured exception handling statement.
Declaration
public static TryBuilder Try(Action scope)
Parameters
Type | Name | Description |
---|---|---|
Action | scope |
|
Returns
Type | Description |
---|---|
TryBuilder | Structured exception handling builder. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Attempts to call this method out of lexical scope. |
See Also
| Edit this page View SourceTry(Expression)
Adds structured exception handling statement.
Declaration
public static TryBuilder Try(Expression body)
Parameters
Type | Name | Description |
---|---|---|
Expression | body |
|
Returns
Type | Description |
---|---|
TryBuilder | Structured exception handling builder. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Attempts to call this method out of lexical scope. |
See Also
| Edit this page View SourceUsing(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
| Edit this page View SourceUsing(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
| Edit this page View SourceVariable(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. |
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
| Edit this page View SourceWhile(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
| Edit this page View SourceWith(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
| Edit this page View SourceWriteError(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. |
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. |