public static Expression TryConvert(DecompilerContext context, Expression expr)
		{
			Expression converted = new ExpressionTreeConverter(context).Convert(expr);
			if (converted != null) {
				converted.AddAnnotation(new ExpressionTreeLambdaAnnotation());
			}
			return converted;
		}
コード例 #2
0
        public static Expression TryConvert(DecompilerContext context, Expression expr, StringBuilder sb)
        {
            Expression converted = new ExpressionTreeConverter(context, sb).Convert(expr);

            if (converted != null)
            {
                converted.AddAnnotation(new ExpressionTreeLambdaAnnotation());
            }
            return(converted);
        }
コード例 #3
0
 public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
 {
     if (context.Settings.ExpressionTrees && ExpressionTreeConverter.CouldBeExpressionTree(invocationExpression))
     {
         Expression converted = ExpressionTreeConverter.TryConvert(context, invocationExpression);
         if (converted != null)
         {
             invocationExpression.ReplaceWith(converted);
             return(converted.AcceptVisitor(this, data));
         }
     }
     return(base.VisitInvocationExpression(invocationExpression, data));
 }
コード例 #4
0
 public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
 {
     if (context.Settings.ExpressionTrees && ExpressionTreeConverter.CouldBeExpressionTree(invocationExpression))
     {
         Expression converted = ExpressionTreeConverter.TryConvert(context, invocationExpression);
         if (converted != null)
         {
             //TODO: Do we need to preserve ILRanges or is it taken care of by TryConvert?
             invocationExpression.ReplaceWith(converted);
             return(converted.AcceptVisitor(this, data));
         }
     }
     return(base.VisitInvocationExpression(invocationExpression, data));
 }
コード例 #5
0
        public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
        {
            if (context.Settings.ExpressionTrees && ExpressionTreeConverter.CouldBeExpressionTree(invocationExpression))
            {
                Expression converted = ExpressionTreeConverter.TryConvert(context, invocationExpression);
                if (converted != null)
                {
                    invocationExpression.ReplaceWith(converted);
                    return(converted.AcceptVisitor(this, data));
                }
            }
            var definition = invocationExpression.Annotation <MethodDefinition>();

            if (definition != null)
            {
                //Handle hoisted base calls from yield return compiler generated class (can be generated by both Mono and Roslyn)
                if (definition.DeclaringType == context.CurrentType && definition.IsCompilerGenerated())
                {
                    DecompilerContext subContext = context.Clone();
                    subContext.CurrentMethod        = definition;
                    subContext.CurrentMethodIsAsync = false;
                    subContext.ReservedVariableNames.AddRange(currentlyUsedVariableNames);
                    var            parameters = AstBuilder.MakeParameters(definition, isLambda: true);
                    BlockStatement body       = AstMethodBodyBuilder.CreateMethodBody(definition, subContext, parameters);
                    TransformationPipeline.RunTransformationsUntil(body, v => v is DelegateConstruction, subContext);

                    if (body.Statements.Count == 1)
                    {
                        var        statement = body.Statements.Single();
                        Expression expr      = null;
                        if (statement is ReturnStatement)
                        {
                            expr = ((ReturnStatement)statement).Expression;
                        }
                        else if (statement is ExpressionStatement)
                        {
                            expr = ((ExpressionStatement)statement).Expression;
                        }
                        if (expr != null)
                        {
                            expr.Remove();
                            invocationExpression.ReplaceWith(expr);
                            return(expr.AcceptVisitor(this, data));
                        }
                    }
                }
            }
            return(base.VisitInvocationExpression(invocationExpression, data));
        }