Show / Hide Table of Contents

Class TypeSubstitutionExpressionVisitor

Visitor to retarget types that occur in an expression tree. Subclasses can customize reflection member resolution.

Inheritance
System.Object
ScopedExpressionVisitorBase
ScopedExpressionVisitor<System.Linq.Expressions.ParameterExpression>
ExpressionVisitorWithReflection
TypeSubstitutionExpressionVisitor
EntityTypeSubstitutor
StructuralTypeSubstitutionExpressionVisitor
Inherited Members
ExpressionVisitorWithReflection.VisitBinary(BinaryExpression)
ExpressionVisitorWithReflection.MakeBinary(ExpressionType, Expression, Expression, Boolean, MethodInfo, LambdaExpression)
ExpressionVisitorWithReflection.VisitBlockCore(BlockExpression)
ExpressionVisitorWithReflection.MakeBlock(Type, IEnumerable<ParameterExpression>, IEnumerable<Expression>)
ExpressionVisitorWithReflection.VisitCatchBlockCore(CatchBlock)
ExpressionVisitorWithReflection.MakeCatchBlock(Type, ParameterExpression, Expression, Expression)
ExpressionVisitorWithReflection.VisitConditional(ConditionalExpression)
ExpressionVisitorWithReflection.MakeConditional(Expression, Expression, Expression, Type)
ExpressionVisitorWithReflection.VisitConstant(ConstantExpression)
ExpressionVisitorWithReflection.VisitDefault(DefaultExpression)
ExpressionVisitorWithReflection.MakeDefault(Type)
ExpressionVisitorWithReflection.MakeDynamic(CallSiteBinder, Type, IEnumerable<Expression>)
ExpressionVisitorWithReflection.VisitElementInit(ElementInit)
ExpressionVisitorWithReflection.MakeElementInit(MethodInfo, IEnumerable<Expression>)
ExpressionVisitorWithReflection.VisitGoto(GotoExpression)
ExpressionVisitorWithReflection.MakeGoto(GotoExpressionKind, LabelTarget, Expression, Type)
ExpressionVisitorWithReflection.VisitIndex(IndexExpression)
ExpressionVisitorWithReflection.MakeIndex(Expression, PropertyInfo, IEnumerable<Expression>)
ExpressionVisitorWithReflection.VisitInvocation(InvocationExpression)
ExpressionVisitorWithReflection.MakeInvocation(Expression, IEnumerable<Expression>)
ExpressionVisitorWithReflection.VisitLabel(LabelExpression)
ExpressionVisitorWithReflection.MakeLabel(LabelTarget, Expression)
ExpressionVisitorWithReflection.VisitLabelTarget(LabelTarget)
ExpressionVisitorWithReflection.MakeLabelTarget(Type, String)
ExpressionVisitorWithReflection.VisitLambdaCore<T>(Expression<T>)
ExpressionVisitorWithReflection.MakeLambda(Type, Expression, String, Boolean, IEnumerable<ParameterExpression>)
ExpressionVisitorWithReflection.VisitListInit(ListInitExpression)
ExpressionVisitorWithReflection.MakeListInit(NewExpression, IEnumerable<ElementInit>)
ExpressionVisitorWithReflection.VisitLoop(LoopExpression)
ExpressionVisitorWithReflection.MakeLoop(Expression, LabelTarget, LabelTarget)
ExpressionVisitorWithReflection.VisitMember(MemberExpression)
ExpressionVisitorWithReflection.MakeMember(Expression, MemberInfo)
ExpressionVisitorWithReflection.VisitMemberAssignment(MemberAssignment)
ExpressionVisitorWithReflection.MakeMemberAssignment(MemberInfo, Expression)
ExpressionVisitorWithReflection.VisitMemberInit(MemberInitExpression)
ExpressionVisitorWithReflection.MakeMemberInit(NewExpression, IEnumerable<MemberBinding>)
ExpressionVisitorWithReflection.VisitMemberListBinding(MemberListBinding)
ExpressionVisitorWithReflection.MakeMemberListBinding(MemberInfo, IEnumerable<ElementInit>)
ExpressionVisitorWithReflection.VisitMemberMemberBinding(MemberMemberBinding)
ExpressionVisitorWithReflection.MakeMemberMemberBinding(MemberInfo, IEnumerable<MemberBinding>)
ExpressionVisitorWithReflection.VisitMethodCall(MethodCallExpression)
ExpressionVisitorWithReflection.MakeMethodCall(Expression, MethodInfo, IEnumerable<Expression>)
ExpressionVisitorWithReflection.VisitNew(NewExpression)
ExpressionVisitorWithReflection.MakeNew(ConstructorInfo, IEnumerable<Expression>, IEnumerable<MemberInfo>)
ExpressionVisitorWithReflection.MakeNew(Type)
ExpressionVisitorWithReflection.VisitNewArray(NewArrayExpression)
ExpressionVisitorWithReflection.MakeNewArray(ExpressionType, Type, IEnumerable<Expression>)
ExpressionVisitorWithReflection.VisitParameter(ParameterExpression)
ExpressionVisitorWithReflection.GetState(ParameterExpression)
ExpressionVisitorWithReflection.VisitRuntimeVariables(RuntimeVariablesExpression)
ExpressionVisitorWithReflection.MakeRuntimeVariables(IEnumerable<ParameterExpression>)
ExpressionVisitorWithReflection.VisitSwitch(SwitchExpression)
ExpressionVisitorWithReflection.MakeSwitch(Type, Expression, Expression, MethodInfo, IEnumerable<SwitchCase>)
ExpressionVisitorWithReflection.VisitSwitchCase(SwitchCase)
ExpressionVisitorWithReflection.MakeSwitchCase(Expression, IEnumerable<Expression>)
ExpressionVisitorWithReflection.VisitTry(TryExpression)
ExpressionVisitorWithReflection.MakeTry(Type, Expression, Expression, Expression, IEnumerable<CatchBlock>)
ExpressionVisitorWithReflection.VisitTypeBinary(TypeBinaryExpression)
ExpressionVisitorWithReflection.MakeTypeBinary(ExpressionType, Expression, Type)
ExpressionVisitorWithReflection.VisitUnary(UnaryExpression)
ExpressionVisitorWithReflection.MakeUnary(ExpressionType, Expression, Type, MethodInfo)
ExpressionVisitorWithReflection.VisitBinder(CallSiteBinder)
ExpressionVisitorWithReflection.VisitIfNotNull<T>(T, Func<T, T>)
ScopedExpressionVisitor<ParameterExpression>.TryLookup(ParameterExpression, ParameterExpression)
ScopedExpressionVisitor<ParameterExpression>.Push(IEnumerable<ParameterExpression>)
ScopedExpressionVisitor<ParameterExpression>.Push(IEnumerable<KeyValuePair<ParameterExpression, ParameterExpression>>)
ScopedExpressionVisitor<ParameterExpression>.Pop()
ScopedExpressionVisitor<ParameterExpression>.GlobalScope
ScopedExpressionVisitorBase.VisitBlock(BlockExpression)
ScopedExpressionVisitorBase.VisitCatchBlock(CatchBlock)
ScopedExpressionVisitorBase.VisitLambda<T>(Expression<T>)
Namespace: System.Linq.CompilerServices
Assembly: Nuqleon.Linq.CompilerServices.dll
Syntax
public class TypeSubstitutionExpressionVisitor : ExpressionVisitorWithReflection

Constructors

TypeSubstitutionExpressionVisitor(IDictionary<Type, Type>)

Creates a new type substitution expression visitor with the specified type map.

Declaration
public TypeSubstitutionExpressionVisitor(IDictionary<Type, Type> typeMap)
Parameters
Type Name Description
System.Collections.Generic.IDictionary<System.Type, System.Type> typeMap

Dictionary to map source types onto target types.

TypeSubstitutionExpressionVisitor(TypeSubstitutor)

Creates a new type substitution expression visitor with the specified type substitutor.

Declaration
public TypeSubstitutionExpressionVisitor(TypeSubstitutor typeSubstitutor)
Parameters
Type Name Description
TypeSubstitutor typeSubstitutor

Type substitutor to map source types onto target types.

Methods

Apply(Expression)

Applies the type substitution to the specified expression.

Declaration
public virtual Expression Apply(Expression expression)
Parameters
Type Name Description
System.Linq.Expressions.Expression expression

Expression to rewrite.

Returns
Type Description
System.Linq.Expressions.Expression

Expression with nodes with source types replaced by nodes with the corresponding target types.

ConvertConstant(Object, Type)

Converts a constant value whose constant expression node's type has changed.

Declaration
protected virtual object ConvertConstant(object originalValue, Type newType)
Parameters
Type Name Description
System.Object originalValue

Original value of the constant expression.

System.Type newType

Resolved target type for the constant.

Returns
Type Description
System.Object

Object representing the same value as the original value, but using the specified resolved target type.

ConvertExpression(Expression, Expression, Type)

Converts an expression whose type has changed.

Declaration
protected virtual Expression ConvertExpression(Expression originalExpression, Expression resultExpression, Type newType)
Parameters
Type Name Description
System.Linq.Expressions.Expression originalExpression

Original expression.

System.Linq.Expressions.Expression resultExpression

Rewritten expression which does not conform to the expected type.

System.Type newType

Resolved target type for the expression.

Returns
Type Description
System.Linq.Expressions.Expression

Expression with the same value as the rewritten expression, but using the specified resolved target type.

FailResolveConstructor(ConstructorInfo, Type, Type[])

Reports failure of resolving a constructor after retargeting types, offering a last chance opportunity to resolve the constructor.

Declaration
protected virtual ConstructorInfo FailResolveConstructor(ConstructorInfo originalConstructor, Type declaringType, Type[] parameters)
Parameters
Type Name Description
System.Reflection.ConstructorInfo originalConstructor

Original constructor.

System.Type declaringType

Retargeted declaring type.

System.Type[] parameters

Retargeted parameter types.

Returns
Type Description
System.Reflection.ConstructorInfo

New constructor to use. By default, this method throws an exception to report the resolution failure.

Exceptions
Type Condition
System.InvalidOperationException

Thrown to report the resolution failure.

FailResolveField(FieldInfo, Type, Type)

Reports failure of resolving a field after retargeting types, offering a last chance opportunity to resolve the field.

Declaration
protected virtual MemberInfo FailResolveField(FieldInfo originalField, Type declaringType, Type fieldType)
Parameters
Type Name Description
System.Reflection.FieldInfo originalField

Original field.

System.Type declaringType

Retargeted declaring type.

System.Type fieldType

Retargeted field type.

Returns
Type Description
System.Reflection.MemberInfo

New field to use. By default, this method throws an exception to report the resolution failure.

Exceptions
Type Condition
System.InvalidOperationException

Thrown to report the resolution failure.

FailResolveMethod(MethodInfo, Type, Type[], Type[], Type)

Reports failure of resolving a method after retargeting types, offering a last chance opportunity to resolve the method.

Declaration
protected virtual MethodInfo FailResolveMethod(MethodInfo originalMethod, Type declaringType, Type[] genericArguments, Type[] parameters, Type returnType)
Parameters
Type Name Description
System.Reflection.MethodInfo originalMethod

Original method.

System.Type declaringType

Retargeted declaring type.

System.Type[] genericArguments

Retargeted generic argument types.

System.Type[] parameters

Retargeted parameter types.

System.Type returnType

Retargeted return type.

Returns
Type Description
System.Reflection.MethodInfo

New method to use. By default, this method throws an exception to report the resolution failure.

Exceptions
Type Condition
System.InvalidOperationException

Thrown to report the resolution failure.

FailResolveProperty(PropertyInfo, Type, Type, Type[])

Reports failure of resolving a property after retargeting types, offering a last chance opportunity to resolve the property.

Declaration
protected virtual MemberInfo FailResolveProperty(PropertyInfo originalProperty, Type declaringType, Type propertyType, Type[] indexerParameters)
Parameters
Type Name Description
System.Reflection.PropertyInfo originalProperty

Original property.

System.Type declaringType

Retargeted declaring type.

System.Type propertyType

Retargeted property type.

System.Type[] indexerParameters

Retargeted indexer parameter types.

Returns
Type Description
System.Reflection.MemberInfo

New property to use. By default, this method throws an exception to report the resolution failure.

Exceptions
Type Condition
System.InvalidOperationException

Thrown to report the resolution failure.

MakeConstant(Object, Type)

Creates a constant expression.

Declaration
protected override Expression MakeConstant(object value, Type type)
Parameters
Type Name Description
System.Object value

Value of the constant expression.

System.Type type

Type of the constant expression.

Returns
Type Description
System.Linq.Expressions.Expression

New constant expression node.

Overrides
ExpressionVisitorWithReflection.MakeConstant(Object, Type)

ResolveConstructor(ConstructorInfo, Type, Type[])

Resolves a constructor after retargeting types.

Declaration
protected virtual ConstructorInfo ResolveConstructor(ConstructorInfo originalConstructor, Type declaringType, Type[] parameters)
Parameters
Type Name Description
System.Reflection.ConstructorInfo originalConstructor

Original constructor.

System.Type declaringType

Retargeted declaring type.

System.Type[] parameters

Retargeted parameter types.

Returns
Type Description
System.Reflection.ConstructorInfo

New constructor to use.

ResolveField(FieldInfo, Type, Type)

Resolves a field after retargeting types.

Declaration
protected virtual MemberInfo ResolveField(FieldInfo originalField, Type declaringType, Type fieldType)
Parameters
Type Name Description
System.Reflection.FieldInfo originalField

Original field.

System.Type declaringType

Retargeted declaring type.

System.Type fieldType

Retargeted field type.

Returns
Type Description
System.Reflection.MemberInfo

New field to use.

ResolveMethod(MethodInfo, Type, Type[], Type[], Type)

Resolves a method after retargeting types.

Declaration
protected virtual MethodInfo ResolveMethod(MethodInfo originalMethod, Type declaringType, Type[] genericArguments, Type[] parameters, Type returnType)
Parameters
Type Name Description
System.Reflection.MethodInfo originalMethod

Original method.

System.Type declaringType

Retargeted declaring type.

System.Type[] genericArguments

Retargeted generic argument types.

System.Type[] parameters

Retargeted parameter types.

System.Type returnType

Retargeted return type.

Returns
Type Description
System.Reflection.MethodInfo

New method to use.

ResolveProperty(PropertyInfo, Type, Type, Type[])

Resolves a property after retargeting types.

Declaration
protected virtual MemberInfo ResolveProperty(PropertyInfo originalProperty, Type declaringType, Type propertyType, Type[] indexerParameters)
Parameters
Type Name Description
System.Reflection.PropertyInfo originalProperty

Original property.

System.Type declaringType

Retargeted declaring type.

System.Type propertyType

Retargeted property type.

System.Type[] indexerParameters

Retargeted indexer parameter types.

Returns
Type Description
System.Reflection.MemberInfo

New property to use.

ResolveType(Type)

Resolves a type for rewriting of the expression tree.

Declaration
protected virtual Type ResolveType(Type originalType)
Parameters
Type Name Description
System.Type originalType

Original type.

Returns
Type Description
System.Type

New type to use.

Visit(Expression)

Visits the expression to rewrite types.

Declaration
public override Expression Visit(Expression node)
Parameters
Type Name Description
System.Linq.Expressions.Expression node

Expression to visit.

Returns
Type Description
System.Linq.Expressions.Expression

Expression with types rewritten.

VisitConstructor(ConstructorInfo)

Visits a constructor. When overridden, other visit methods should be overridden appropriately to ensure consistent typing.

Declaration
protected override ConstructorInfo VisitConstructor(ConstructorInfo constructor)
Parameters
Type Name Description
System.Reflection.ConstructorInfo constructor

Constructor to visit.

Returns
Type Description
System.Reflection.ConstructorInfo

Result of the visit.

Overrides
ExpressionVisitorWithReflection.VisitConstructor(ConstructorInfo)

VisitDynamic(DynamicExpression)

Visits a dynamic expression in order to rewrite the type while retaining the binder.

Declaration
protected override Expression VisitDynamic(DynamicExpression node)
Parameters
Type Name Description
System.Linq.Expressions.DynamicExpression node

The node to visit.

Returns
Type Description
System.Linq.Expressions.Expression

Result of the visit.

Overrides
ExpressionVisitorWithReflection.VisitDynamic(DynamicExpression)

VisitField(FieldInfo)

Visits a field. When overridden, other visit methods should be overridden appropriately to ensure consistent typing.

Declaration
protected virtual MemberInfo VisitField(FieldInfo field)
Parameters
Type Name Description
System.Reflection.FieldInfo field

Field to visit.

Returns
Type Description
System.Reflection.MemberInfo

Result of the visit.

VisitMember(MemberInfo)

Visits a member. When overridden, other visit methods should be overridden appropriately to ensure consistent typing.

Declaration
protected override MemberInfo VisitMember(MemberInfo member)
Parameters
Type Name Description
System.Reflection.MemberInfo member

Member to visit.

Returns
Type Description
System.Reflection.MemberInfo

Result of the visit.

Overrides
ExpressionVisitorWithReflection.VisitMember(MemberInfo)

VisitMethod(MethodInfo)

Visits a method. When overridden, other visit methods should be overridden appropriately to ensure consistent typing.

Declaration
protected override MethodInfo VisitMethod(MethodInfo method)
Parameters
Type Name Description
System.Reflection.MethodInfo method

Method to visit.

Returns
Type Description
System.Reflection.MethodInfo

Result of the visit.

Overrides
ExpressionVisitorWithReflection.VisitMethod(MethodInfo)

VisitProperty(PropertyInfo)

Visits a property. When overridden, other visit methods should be overridden appropriately to ensure consistent typing.

Declaration
protected override MemberInfo VisitProperty(PropertyInfo property)
Parameters
Type Name Description
System.Reflection.PropertyInfo property

Property to visit.

Returns
Type Description
System.Reflection.MemberInfo

Result of the visit.

Overrides
ExpressionVisitorWithReflection.VisitProperty(PropertyInfo)

VisitType(Type)

Visits a type. When overridden, other visit methods should be overridden appropriately to ensure consistent typing.

Declaration
protected override Type VisitType(Type type)
Parameters
Type Name Description
System.Type type

Type to visit.

Returns
Type Description
System.Type

Result of the visit.

Overrides
ExpressionVisitorWithReflection.VisitType(Type)
In This Article
Back to top Generated by DocFX