public override Expression CreateExpressionTree(ResolveContext ec) { Arguments args = new Arguments(2); args.Add(new Argument(new TypeOf(type, loc))); if (method_group.InstanceExpression == null) { args.Add(new Argument(new NullLiteral(loc))); } else { args.Add(new Argument(method_group.InstanceExpression)); } Expression ma; var create_v45 = ec.Module.PredefinedMembers.MethodInfoCreateDelegate.Get(); if (create_v45 != null) { // // .NET 4.5 has better API but it produces different instance than Delegate::CreateDelegate // and because csc uses this enhancement we have to as well to be fully compatible // var mg = MethodGroupExpr.CreatePredefined(create_v45, create_v45.DeclaringType, loc); mg.InstanceExpression = method_group.CreateExpressionTree(ec); ma = mg; } else { ma = new MemberAccess(new MemberAccess(new QualifiedAliasMember("global", "System", loc), "Delegate", loc), "CreateDelegate", loc); args.Add(new Argument(method_group.CreateExpressionTree(ec))); } Expression e = new Invocation(ma, args).Resolve(ec); if (e == null) { return(null); } e = Convert.ExplicitConversion(ec, e, type, loc); if (e == null) { return(null); } return(e.CreateExpressionTree(ec)); }
public override Expression CreateExpressionTree(ResolveContext ec) { MemberAccess ma = new MemberAccess(new MemberAccess(new QualifiedAliasMember("global", "System", loc), "Delegate", loc), "CreateDelegate", loc); Arguments args = new Arguments(3); args.Add(new Argument(new TypeOf(type, loc))); if (method_group.InstanceExpression == null) { args.Add(new Argument(new NullLiteral(loc))); } else { args.Add(new Argument(method_group.InstanceExpression)); } args.Add(new Argument(method_group.CreateExpressionTree(ec))); Expression e = new Invocation(ma, args).Resolve(ec); if (e == null) { return(null); } e = Convert.ExplicitConversion(ec, e, type, loc); if (e == null) { return(null); } return(e.CreateExpressionTree(ec)); }
Expression CreateExpressionTree (ResolveContext ec, MethodGroupExpr method) { string method_name; bool lift_arg = false; switch (oper) { case Operator.Addition: if (method == null && ec.HasSet (ResolveContext.Options.CheckedScope) && !IsFloat (type)) method_name = "AddChecked"; else method_name = "Add"; break; case Operator.BitwiseAnd: method_name = "And"; break; case Operator.BitwiseOr: method_name = "Or"; break; case Operator.Division: method_name = "Divide"; break; case Operator.Equality: method_name = "Equal"; lift_arg = true; break; case Operator.ExclusiveOr: method_name = "ExclusiveOr"; break; case Operator.GreaterThan: method_name = "GreaterThan"; lift_arg = true; break; case Operator.GreaterThanOrEqual: method_name = "GreaterThanOrEqual"; lift_arg = true; break; case Operator.Inequality: method_name = "NotEqual"; lift_arg = true; break; case Operator.LeftShift: method_name = "LeftShift"; break; case Operator.LessThan: method_name = "LessThan"; lift_arg = true; break; case Operator.LessThanOrEqual: method_name = "LessThanOrEqual"; lift_arg = true; break; case Operator.LogicalAnd: method_name = "AndAlso"; break; case Operator.LogicalOr: method_name = "OrElse"; break; case Operator.Modulus: method_name = "Modulo"; break; case Operator.Multiply: if (method == null && ec.HasSet (ResolveContext.Options.CheckedScope) && !IsFloat (type)) method_name = "MultiplyChecked"; else method_name = "Multiply"; break; case Operator.RightShift: method_name = "RightShift"; break; case Operator.Subtraction: if (method == null && ec.HasSet (ResolveContext.Options.CheckedScope) && !IsFloat (type)) method_name = "SubtractChecked"; else method_name = "Subtract"; break; default: throw new InternalErrorException ("Unknown expression tree binary operator " + oper); } Arguments args = new Arguments (2); args.Add (new Argument (left.CreateExpressionTree (ec))); args.Add (new Argument (right.CreateExpressionTree (ec))); if (method != null) { if (lift_arg) args.Add (new Argument (new BoolConstant (false, loc))); args.Add (new Argument (method.CreateExpressionTree (ec))); } return CreateExpressionFactoryCall (ec, method_name, args); }
Expression CreateExpressionTree (ResolveContext ec, MethodGroupExpr user_op) { string method_name; switch (Oper) { case Operator.AddressOf: Error_PointerInsideExpressionTree (ec); return null; case Operator.UnaryNegation: if (ec.HasSet (ResolveContext.Options.CheckedScope) && user_op == null && !IsFloat (type)) method_name = "NegateChecked"; else method_name = "Negate"; break; case Operator.OnesComplement: case Operator.LogicalNot: method_name = "Not"; break; case Operator.UnaryPlus: method_name = "UnaryPlus"; break; default: throw new InternalErrorException ("Unknown unary operator " + Oper.ToString ()); } Arguments args = new Arguments (2); args.Add (new Argument (Expr.CreateExpressionTree (ec))); if (user_op != null) args.Add (new Argument (user_op.CreateExpressionTree (ec))); return CreateExpressionFactoryCall (ec, method_name, args); }