Author: jbevain
Date: 2008-02-08 09:30:36 -0500 (Fri, 08 Feb 2008)
New Revision: 95257

Modified:
   trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
   trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
   trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs
   trunk/mcs/class/System.Core/System.Linq.Expressions/InvocationExpression.cs
Log:
2008-02-08  Jb Evain  <[EMAIL PROTECTED]>

        * Expression.cs, InvocationExpression.cs, ExpressionPrinter.cs
                add support for Invoke.



Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog       
2008-02-08 14:30:15 UTC (rev 95256)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog       
2008-02-08 14:30:36 UTC (rev 95257)
@@ -1,3 +1,8 @@
+2008-02-08  Jb Evain  <[EMAIL PROTECTED]>
+
+       * Expression.cs, InvocationExpression.cs, ExpressionPrinter.cs
+               add support for Invoke.
+
 2008-02-04  Jb Evain  <[EMAIL PROTECTED]>
 
        * ExpressionPrinter.cs: fix printing of MemberListBinding.

Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs   
2008-02-08 14:30:15 UTC (rev 95256)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs   
2008-02-08 14:30:36 UTC (rev 95257)
@@ -1158,16 +1158,52 @@
                        return func.MakeGenericType (typeArgs);
                }
 
-               [MonoTODO]
                public static InvocationExpression Invoke (Expression 
expression, params Expression [] arguments)
                {
                        return Invoke (expression, arguments as 
IEnumerable<Expression>);
                }
 
-               [MonoTODO]
+               static Type GetInvokableType (Type t)
+               {
+                       if (typeof (Delegate).IsAssignableFrom (t))
+                               return t;
+
+                       return GetGenericType (t, typeof (Expression<>));
+               }
+
+               static Type GetGenericType (Type t, Type def)
+               {
+                       if (t == null)
+                               return null;
+
+                       if (t.IsGenericType && t.GetGenericTypeDefinition () == 
def)
+                               return t;
+
+                       return GetGenericType (t.BaseType, def);
+               }
+
                public static InvocationExpression Invoke (Expression 
expression, IEnumerable<Expression> arguments)
                {
-                       throw new NotImplementedException ();
+                       if (expression == null)
+                               throw new ArgumentNullException ("expression");
+
+                       var type = GetInvokableType (expression.Type);
+                       if (type == null)
+                               throw new ArgumentException ("The type of the 
expression is not invokable");
+
+                       var args = arguments.ToReadOnlyCollection ();
+                       CheckForNull (args, "arguments");
+
+                       var invoke = type.GetMethod ("Invoke");
+                       if (invoke == null)
+                               throw new ArgumentException ("expression");
+
+                       if (invoke.GetParameters ().Length != args.Count)
+                               throw new InvalidOperationException ("Arguments 
count doesn't match parameters length");
+
+                       CheckMethodArguments (invoke, args);
+
+                       return new InvocationExpression (expression, 
invoke.ReturnType, args);
                }
 
                public static Expression<TDelegate> Lambda<TDelegate> 
(Expression body, params ParameterExpression [] parameters)

Modified: 
trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs    
2008-02-08 14:30:15 UTC (rev 95256)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs    
2008-02-08 14:30:36 UTC (rev 95257)
@@ -37,6 +37,8 @@
 
                StringBuilder builder;
 
+               const string ListSeparator = ", ";
+
                ExpressionPrinter (StringBuilder builder)
                {
                        this.builder = builder;
@@ -296,7 +298,7 @@
                {
                        for (int i = 0; i < list.Count; i++) {
                                if (i > 0)
-                                       Print (", ");
+                                       Print (ListSeparator);
 
                                visitor (list [i]);
                        }
@@ -356,7 +358,15 @@
 
                protected override void VisitInvocation (InvocationExpression 
invocation)
                {
-                       throw new NotImplementedException ();
+                       Print ("Invoke(");
+                       Visit (invocation.Expression);
+
+                       if (invocation.Arguments.Count != 0) {
+                               Print (ListSeparator);
+                               VisitExpressionList (invocation.Arguments);
+                       }
+
+                       Print (")");
                }
        }
 }

Modified: 
trunk/mcs/class/System.Core/System.Linq.Expressions/InvocationExpression.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/InvocationExpression.cs 
2008-02-08 14:30:15 UTC (rev 95256)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/InvocationExpression.cs 
2008-02-08 14:30:36 UTC (rev 95257)
@@ -35,28 +35,27 @@
 
        public sealed class InvocationExpression : Expression {
 
-               Expression lambda;
+               Expression expression;
                ReadOnlyCollection<Expression> arguments;
 
                public Expression Expression {
-                       get { return lambda; }
+                       get { return expression; }
                }
 
                public ReadOnlyCollection<Expression> Arguments {
                        get { return arguments; }
                }
-               
-               internal InvocationExpression (Expression lambda, 
ReadOnlyCollection<Expression> arguments)
-                       : base (ExpressionType.Invoke, lambda.Type)
+
+               internal InvocationExpression (Expression expression, Type 
type, ReadOnlyCollection<Expression> arguments)
+                       : base (ExpressionType.Invoke, type)
                {
-                       this.lambda = lambda;
+                       this.expression = expression;
                        this.arguments = arguments;
                }
-               
+
                internal override void Emit (EmitContext ec)
                {
                        throw new NotImplementedException ();
                }
-               
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to