Parameter() public static method

public static Parameter ( ICSharpCode.NRefactory.CSharp parameter, IScope scope, INRefcatoryExpressionVisitor visitor ) : ParameterDecalration
parameter ICSharpCode.NRefactory.CSharp
scope IScope
visitor INRefcatoryExpressionVisitor
return ParameterDecalration
        private Expression ReduceBaseAssignment(Base expression)
        {
            Type             returnType       = null;
            Delegate         @delegate        = null;
            MethodInfo       methodInfo       = null;
            ILGenerator      ilGenerator      = null;
            DynamicMethod    dynamicMethod    = null;
            Type             delegateType     = typeof(Func <, ,>);
            MethodDefinition methodDefinition = null;
            var expressionType = expression.Type;
            ParameterExpression assignedValue = null;
            var propertyReference             = _memberReferenceExpression.Annotation <PropertyDefinition>();

            methodDefinition = propertyReference.GetMethod;
            methodInfo       = methodDefinition.GetActualMethod <MethodInfo>();
            returnType       = InternalType = methodInfo.ReturnType;
            assignedValue    = AstExpression.Parameter(returnType);
            methodDefinition = propertyReference.SetMethod;
            methodInfo       = methodDefinition.GetActualMethod <MethodInfo>();

            dynamicMethod = new DynamicMethod(string.Format("Base_{0}", methodInfo.Name), returnType, new Type[] { expressionType, returnType }, expressionType);
            ilGenerator   = dynamicMethod.GetILGenerator();
            ilGenerator.Emit(OpCodes.Ldarg_0);
            ilGenerator.Emit(OpCodes.Ldarg_1);
            ilGenerator.EmitCall(OpCodes.Call, methodInfo, null);
            ilGenerator.Emit(OpCodes.Ldarg_1);
            ilGenerator.Emit(OpCodes.Ret);

            delegateType = delegateType.MakeGenericType(expressionType, returnType, returnType);
            @delegate    = dynamicMethod.CreateDelegate(delegateType);

            return(AstExpression.Lambda(
                       AstExpression.GetFuncType(returnType, returnType),
                       AstExpression.Invoke(AstExpression.Constant(@delegate), Expression, assignedValue),
                       new ParameterExpression[] { assignedValue },
                       ParentScope, Visitor));
        }
Example #2
0
 protected override Expression CreateDeclaration()
 {
     return(AstExpression.Parameter(DeclarationValue, ParentScope, Visitor));
 }