Author: jbevain
Date: 2008-02-02 08:43:10 -0500 (Sat, 02 Feb 2008)
New Revision: 94622
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 ListBind(MemberInfo,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:42:33 UTC (rev 94621)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
2008-02-02 13:43:10 UTC (rev 94622)
@@ -1,5 +1,9 @@
2008-02-02 Jb Evain <[EMAIL PROTECTED]>
+ * Expression.cs: fix ListBind(MemberInfo,IEnumerable<ElementInit>).
+
+2008-02-02 Jb Evain <[EMAIL PROTECTED]>
+
* Expression.cs: fix ListBind(MethodInfo,IEnumerable<ElementInit>).
2008-02-01 Olivier Dufour <[EMAIL PROTECTED]>
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:42:33 UTC (rev 94621)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
2008-02-02 13:43:10 UTC (rev 94622)
@@ -1066,7 +1066,7 @@
throw new ArgumentException ("addMethod must be
an instance method", "addMethod");
var args = arguments.ToReadOnlyCollection ();
-
+
CheckMethodArguments (addMethod, args);
return new ElementInit (addMethod, args);
@@ -1229,26 +1229,32 @@
return ListBind (member, initializers as
IEnumerable<ElementInit>);
}
+ static void CheckIsAssignableToIEnumerable (Type t)
+ {
+ if (!typeof (IEnumerable).IsAssignableFrom (t))
+ throw new ArgumentException (string.Format
("Type {0} doesn't implemen IEnumerable", t));
+ }
+
public static MemberListBinding ListBind (MemberInfo member,
IEnumerable<ElementInit> initializers)
{
if (member == null)
throw new ArgumentNullException ("member");
- foreach (ElementInit elt in initializers) {
- if (elt == null)
- throw new ArgumentNullException
("initializers");
+
+ var inits = initializers.ToReadOnlyCollection ();
+ CheckForNull (inits, "initializers");
+
+ switch (member.MemberType) {
+ case MemberTypes.Field:
+ CheckIsAssignableToIEnumerable ((member as
FieldInfo).FieldType);
+ break;
+ case MemberTypes.Property:
+ CheckIsAssignableToIEnumerable ((member as
PropertyInfo).PropertyType);
+ break;
+ default:
+ throw new ArgumentException ("member");
}
- Type mbrType;
- if (member.MemberType == MemberTypes.Field)
- mbrType = ((FieldInfo)member).FieldType;
- else if (member.MemberType != MemberTypes.Property)
- 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 ());
+ return new MemberListBinding (member, inits);
}
public static MemberListBinding ListBind (MethodInfo
propertyAccessor, params ElementInit [] initializers)
@@ -1275,8 +1281,7 @@
if (prop == null)
throw new ArgumentException
("propertyAccessor");
- if (!typeof (IEnumerable).IsAssignableFrom
(prop.PropertyType))
- throw new ArgumentException
("propertyAccessor");
+ CheckIsAssignableToIEnumerable (prop.PropertyType);
return new MemberListBinding (prop, inits);
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches