Class SwitchBuilder
Represents selection statement that chooses a single section to execute from a list of candidates based on a pattern matching.
Inherited Members
Namespace: DotNext.Metaprogramming
Assembly: DotNext.Metaprogramming.dll
Syntax
public sealed class SwitchBuilder : ExpressionBuilder<SwitchExpression>, ISupplier<SwitchExpression>, IFunctional<Func<SwitchExpression>>
Methods
| Edit this page View SourceCase(IEnumerable<Expression>, Action)
Specifies a pattern to compare to the match expression and action to be executed if matching is successful.
Declaration
public SwitchBuilder Case(IEnumerable<Expression> testValues, Action body)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Expression> | testValues | A list of test values. |
Action | body | The block code to be executed if input value is equal to one of test values. |
Returns
Type | Description |
---|---|
SwitchBuilder | Modified selection builder. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Attempts to call this method out of lexical scope. |
Case(IEnumerable<Expression>, Expression)
Specifies a pattern to compare to the match expression and expression to be returned if matching is successful.
Declaration
public SwitchBuilder Case(IEnumerable<Expression> testValues, Expression body)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Expression> | testValues | A list of test values. |
Expression | body | The expression to be returned from selection statement. |
Returns
Type | Description |
---|---|
SwitchBuilder |
|
Case(Expression, Action)
Specifies a pattern to compare to the match expression and action to be executed if matching is successful.
Declaration
public SwitchBuilder Case(Expression test, Action body)
Parameters
Type | Name | Description |
---|---|---|
Expression | test | Single test value. |
Action | body | The block code to be executed if input value is equal to one of test values. |
Returns
Type | Description |
---|---|
SwitchBuilder | Modified selection builder. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Attempts to call this method out of lexical scope. |
Case(Expression, Expression)
Specifies a pattern to compare to the match expression and expression to be returned if matching is successful.
Declaration
public SwitchBuilder Case(Expression test, Expression body)
Parameters
Type | Name | Description |
---|---|---|
Expression | test | Single test value. |
Expression | body | The expression to be returned from selection statement. |
Returns
Type | Description |
---|---|
SwitchBuilder |
|
Default(Action)
Specifies the switch section to execute if the match expression doesn't match any other cases.
Declaration
public SwitchBuilder Default(Action body)
Parameters
Type | Name | Description |
---|---|---|
Action | body | The block code to be executed if input value is equal to one of test values. |
Returns
Type | Description |
---|---|
SwitchBuilder | Modified selection builder. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Attempts to call this method out of lexical scope. |
Default(Expression)
Specifies the switch section to execute if the match expression doesn't match any other cases.
Declaration
public SwitchBuilder Default(Expression body)
Parameters
Type | Name | Description |
---|---|---|
Expression | body | The expression to be returned from selection statement in default case. |
Returns
Type | Description |
---|---|
SwitchBuilder |
|