Author: jbevain
Date: 2008-02-02 08:28:55 -0500 (Sat, 02 Feb 2008)
New Revision: 94618

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

        * Expression.cs: fix ListInit(MethodInfo,IEnumerable<ElementInit>).



Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog       
2008-02-02 13:28:16 UTC (rev 94617)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog       
2008-02-02 13:28:55 UTC (rev 94618)
@@ -1,3 +1,7 @@
+2008-02-02  Jb Evain  <[EMAIL PROTECTED]>
+
+       * Expression.cs: fix ListInit(MethodInfo,IEnumerable<ElementInit>).
+
 2008-02-01  Olivier Dufour  <[EMAIL PROTECTED]>
 
        * Expression.cs, ExpressionPrinter.cs:Add ListBind

Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs   
2008-02-02 13:28:16 UTC (rev 94617)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs   
2008-02-02 13:28:55 UTC (rev 94618)
@@ -28,6 +28,7 @@
 //
 
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Linq;
@@ -1063,9 +1064,9 @@
                                throw new ArgumentException ("addMethod");
                        if (addMethod.IsStatic)
                                throw new ArgumentException ("addMethod must be 
an instance method", "addMethod");
-                       
+
                        var args = arguments.ToReadOnlyCollection ();
-                           
+                       
                        CheckMethodArguments (addMethod, args);
 
                        return new ElementInit (addMethod, args);
@@ -1157,28 +1158,15 @@
                        return func.MakeGenericType (typeArgs);
                }
 
+               [MonoTODO]
                public static InvocationExpression Invoke (Expression 
expression, params Expression [] arguments)
                {
                        return Invoke (expression, arguments as 
IEnumerable<Expression>);
                }
 
+               [MonoTODO]
                public static InvocationExpression Invoke (Expression 
expression, IEnumerable<Expression> arguments)
                {
-                       /*if (expression == null)
-                               throw new ArgumentNullException ("expression");
-                       System.Delegate delegateObj;
-                       if (expression.Type.IsSubclassOf 
(typeof(Expression<object>))) {//not sure here
-                               delegateObj = 
((Expression<System.Delegate>)expression).Compile ();//not sure here too
-                       } else if (expression.type.IsSubclassOf 
(typeof(System.Delegate))) {
-                               delegateObj = 
(System.Delegate)Activator.CreateInstance(expression.type);
-                       } else
-                               throw new ArgumentException ("expression");
-                       
-                       var args = arguments.ToReadOnlyCollection ();
-                       
-                       CheckMethodArguments (delegateObj.Method, args);
-                       
-                       return new InvocationExpression (expression, args);*/
                        throw new NotImplementedException ();
                }
 
@@ -1256,10 +1244,10 @@
                                mbrType = ((PropertyInfo)member).PropertyType;
                        else
                                throw new ArgumentException ("Member must be a 
field or a property");
-                       
+
                        if 
(!mbrType.IsSubclassOf(typeof(System.Collections.IEnumerable)))
                                throw new ArgumentException ("Member must 
inherite from IEnumerable");
-                                               
+
                        return new MemberListBinding (member, 
initializers.ToReadOnlyCollection ());
                }
 
@@ -1268,33 +1256,29 @@
                        return ListBind (propertyAccessor, initializers as 
IEnumerable<ElementInit>);
                }
 
+               static void CheckForNull<T> (ReadOnlyCollection<T> collection, 
string name) where T : class
+               {
+                       foreach (var t in collection)
+                               if (t == null)
+                                       throw new ArgumentNullException (name);
+               }
+
                public static MemberListBinding ListBind (MethodInfo 
propertyAccessor, IEnumerable<ElementInit> initializers)
                {
                        if (propertyAccessor == null)
                                throw new ArgumentNullException 
("propertyAccessor");
-                       foreach (ElementInit elt in initializers) {
-                               if (elt == null)
-                                       throw new ArgumentNullException 
("initializers");
-                       }
-                       if(propertyAccessor.IsSpecialName) {
-                               Type propType = null;
-                               ParameterInfo[] parameters;
-                               if (propertyAccessor.Name.StartsWith ("get_")) {
-                                       parameters = 
propertyAccessor.GetParameters ();
-                                       if (parameters.Length != 0)
-                                               throw new ArgumentException 
("PropertyAccessor must be a property accessor");
-                                       propType = propertyAccessor.ReturnType;
-                               } else if (propertyAccessor.Name.StartsWith 
("set_")) {
-                                       parameters = 
propertyAccessor.GetParameters ();
-                                       if (parameters.Length != 1)
-                                               throw new ArgumentException 
("PropertyAccessor must be a property accessor");
-                                       propType = parameters[0].ParameterType;
-                               }
-                               if (!propType.IsSubclassOf(typeof 
(System.Collections.IEnumerable)))
-                                       throw new ArgumentException ("The type 
of the property of propertyAccessor must implement IEnumerable");
-                               return new MemberListBinding (propertyAccessor, 
initializers.ToReadOnlyCollection());
-                       }
-                       throw new ArgumentException ("propertyAccessor must be 
a property accessor");
+
+                       var inits = initializers.ToReadOnlyCollection ();
+                       CheckForNull (inits, "initializers");
+
+                       var prop = GetAssociatedProperty (propertyAccessor);
+                       if (prop == null)
+                               throw new ArgumentException 
("propertyAccessor");
+
+                       if (!typeof (IEnumerable).IsAssignableFrom 
(prop.PropertyType))
+                               throw new ArgumentException 
("propertyAccessor");
+
+                       return new MemberListBinding (prop, inits);
                }
 
                [MonoTODO]

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

Reply via email to