Class TypeSubstitutionExpressionVisitor
Visitor to retarget types that occur in an expression tree. Subclasses can customize reflection member resolution.
Inheritance
Inherited Members
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
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
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
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
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
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
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. |