private Expression GetMethodHandleExpression(MethodReference methodReference, IEnumerable<Instruction> instructions) { TypeDefinition corlibTypeTypeDefinition = GetSystemTypeTypeDefinition(); string[] parametersNames = methodReference.HasParameters ? new string[] { "System.String", "System.Type[]" } : new string[] { "System.String" }; MethodReference getMethodReference = GetSystemTypeMethodReference(corlibTypeTypeDefinition, "GetMethod", parametersNames); MethodReference getMethodHandleReference = GetHandlePropertyGetterReference(typeof(System.Reflection.MethodBase), "get_MethodHandle"); TypeOfExpression typeOfExpression = new TypeOfExpression(methodReference.DeclaringType, null); MethodReferenceExpression getMethodMethodReferenceExpression = new MethodReferenceExpression(typeOfExpression, getMethodReference, null); MethodInvocationExpression getMethodMethodInvocationExpression = new MethodInvocationExpression(getMethodMethodReferenceExpression, null); LiteralExpression argument = new LiteralExpression(methodReference.Name, this.typeSystem, null); getMethodMethodInvocationExpression.Arguments.Add(argument); if (methodReference.HasParameters) { BlockExpression blockExpression = new BlockExpression(null); foreach (ParameterDefinition parameter in methodReference.Parameters) { blockExpression.Expressions.Add(new TypeOfExpression(parameter.ParameterType, null)); } InitializerExpression initializer = new InitializerExpression(blockExpression, InitializerType.ArrayInitializer); ArrayCreationExpression getMethodTypeParametersArray = new ArrayCreationExpression(corlibTypeTypeDefinition, initializer, null); getMethodTypeParametersArray.Dimensions.Add(new LiteralExpression(blockExpression.Expressions.Count, this.typeSystem, null)); getMethodMethodInvocationExpression.Arguments.Add(getMethodTypeParametersArray); } MethodReferenceExpression getMethodHandleMethodReferenceExpression = new MethodReferenceExpression(getMethodMethodInvocationExpression, getMethodHandleReference, null); MethodInvocationExpression getMethodHandleMethodInvocationExpression = new MethodInvocationExpression(getMethodHandleMethodReferenceExpression, instructions); PropertyReferenceExpression methodHandlePropertyReferenceExpression = new PropertyReferenceExpression(getMethodHandleMethodInvocationExpression, null); return methodHandlePropertyReferenceExpression; }
public override Expression CloneExpressionOnly() { TypeOfExpression result = new TypeOfExpression(Type, null); return result; }
public override Expression Clone() { TypeOfExpression result = new TypeOfExpression(Type, this.instructions); return result; }
public override void VisitTypeOfExpression(TypeOfExpression node) { WriteKeyword(KeyWordWriter.TypeOf); WriteToken("("); WriteGenericReference(node.Type); WriteToken(")"); }
public override void VisitTypeOfExpression(TypeOfExpression node) { TypesDependingOn.UnionWith(Utilities.GetTypeReferenceTypesDepedningOn(node.Type)); base.VisitTypeOfExpression(node); }
private Expression GetFieldHandleExpression(FieldReference fieldReference, IEnumerable<Instruction> instructions) { TypeDefinition corlibTypeTypeDefinition = GetSystemTypeTypeDefinition(); MethodReference getFieldReference = GetSystemTypeMethodReference(corlibTypeTypeDefinition, "GetField", new string[] { "System.String" }); TypeOfExpression typeOfExpression = new TypeOfExpression(fieldReference.DeclaringType, null); MethodReferenceExpression getFieldMethodReferenceExpression = new MethodReferenceExpression(typeOfExpression, getFieldReference, null); MethodInvocationExpression getFieldInfoInvocation = new MethodInvocationExpression(getFieldMethodReferenceExpression, null); getFieldInfoInvocation.Arguments.Add(new LiteralExpression(fieldReference.Name, this.typeSystem, null)); MethodReference getFieldHandleReference = GetHandlePropertyGetterReference(typeof(System.Reflection.FieldInfo), "get_FieldHandle"); MethodInvocationExpression getFieldHandleInvoke = new MethodInvocationExpression(new MethodReferenceExpression(getFieldInfoInvocation, getFieldHandleReference, null), instructions); return new PropertyReferenceExpression(getFieldHandleInvoke, null); }
private Expression GetTypeHandleExpression(TypeReference typeReference, IEnumerable<Instruction> instructions) { TypeOfExpression typeOfExpression = new TypeOfExpression(typeReference, null); MethodReference getHandleReference = GetHandlePropertyGetterReference(typeof(Type), "get_TypeHandle"); MethodReferenceExpression getHandleReferenceExpression = new MethodReferenceExpression(typeOfExpression, getHandleReference, null); MethodInvocationExpression methodInvoke = new MethodInvocationExpression(getHandleReferenceExpression, instructions); return new PropertyReferenceExpression(methodInvoke, null); }
public virtual void VisitTypeOfExpression(TypeOfExpression node) { }
public override Expression CloneExpressionOnly() { TypeOfExpression result = new TypeOfExpression(Type, null); return(result); }
public override Expression Clone() { TypeOfExpression result = new TypeOfExpression(Type, this.instructions); return(result); }