Class TypeBasedExpressionRewriter
An expression rewriter that rewrites using a set of user defined lambdas that are applied when the runtime type of the expression matches the user supplied value.
Inheritance
Inherited Members
Namespace: System.Linq.CompilerServices
Assembly: Nuqleon.Linq.CompilerServices.dll
Syntax
public class TypeBasedExpressionRewriter : ScopedExpressionVisitor<ParameterExpression>
Constructors
TypeBasedExpressionRewriter()
Instantiates the type-based expression rewriter.
Declaration
public TypeBasedExpressionRewriter()
Methods
Add(Type, Func<Expression, Expression>)
Adds a rewriter for a specified type. The user supplied rewriter is applied whenever an expression type can be assigned to the user supplied type.
Declaration
public void Add(Type type, Func<Expression, Expression> rewriter)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type that triggers the rewriter. |
System.Func<System.Linq.Expressions.Expression, System.Linq.Expressions.Expression> | rewriter | The expression rewriter. |
AddDefinition(Type, Func<Expression, Expression>)
Adds a rewriter for a specified generic type definition. The user supplied rewriter is applied whenever an expression type implements or extends some closure over the user supplied generic type definition.
Declaration
public void AddDefinition(Type type, Func<Expression, Expression> rewriter)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type that triggers the rewriter. |
System.Func<System.Linq.Expressions.Expression, System.Linq.Expressions.Expression> | rewriter | The expression rewriter. |
GetState(ParameterExpression)
Maps the specified parameter on state tracked in the scoped symbol table. This method gets called for each declaration site of a variable.
Declaration
protected override ParameterExpression GetState(ParameterExpression parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.ParameterExpression | parameter | Parameter expression that's being declared. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.ParameterExpression | State to associate with the given parameter. |
Overrides
Visit(Expression)
Visits an expression, looping over the list of user supplied rewriters, and rewriting the expression if the expression type matches any of the supplied rewriters.
Declaration
public override Expression Visit(Expression node)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | node | The expression. |
Returns
Type | Description |
---|---|
System.Linq.Expressions.Expression | The result of the visit. |