Author: jbevain
Date: 2008-02-19 09:11:37 -0500 (Tue, 19 Feb 2008)
New Revision: 96146
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
Log:
2008-02-19 Jb Evain <[EMAIL PROTECTED]>
* Expression.cs, ExpressionPrinter.cs: implement last New
overload for anonymous types.
Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
2008-02-19 13:52:05 UTC (rev 96145)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
2008-02-19 14:11:37 UTC (rev 96146)
@@ -1,3 +1,8 @@
+2008-02-19 Jb Evain <[EMAIL PROTECTED]>
+
+ * Expression.cs, ExpressionPrinter.cs: implement last New
+ overload for anonymous types.
+
2008-02-08 Jb Evain <[EMAIL PROTECTED]>
* Expression.cs, InvocationExpression.cs, ExpressionPrinter.cs
Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
2008-02-19 13:52:05 UTC (rev 96145)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
2008-02-19 14:11:37 UTC (rev 96146)
@@ -1523,16 +1523,53 @@
}
}
- [MonoTODO]
public static NewExpression New (ConstructorInfo constructor,
IEnumerable<Expression> arguments, params MemberInfo [] members)
{
- throw new NotImplementedException ();
+ return New (constructor, arguments, members as
IEnumerable<MemberInfo>);
}
- [MonoTODO]
public static NewExpression New (ConstructorInfo constructor,
IEnumerable<Expression> arguments, IEnumerable<MemberInfo> members)
{
- throw new NotImplementedException ();
+ if (constructor == null)
+ throw new ArgumentNullException ("constructor");
+
+ var args = arguments.ToReadOnlyCollection ();
+ var mmbs = members.ToReadOnlyCollection ();
+
+ CheckForNull (args, "arguments");
+ CheckForNull (mmbs, "members");
+
+ CheckMethodArguments (constructor, args);
+
+ if (args.Count != mmbs.Count)
+ throw new ArgumentException ("Arguments count
does not match members count");
+
+ for (int i = 0; i < mmbs.Count; i++) {
+ var member = mmbs [i];
+ Type type = null;
+ switch (member.MemberType) {
+ case MemberTypes.Field:
+ type = (member as FieldInfo).FieldType;
+ break;
+ case MemberTypes.Method:
+ type = (member as
MethodInfo).ReturnType;
+ break;
+ case MemberTypes.Property:
+ var prop = member as PropertyInfo;
+ if (prop.GetGetMethod (true) == null)
+ throw new ArgumentException
("Property must have a getter");
+
+ type = (member as
PropertyInfo).PropertyType;
+ break;
+ default:
+ throw new ArgumentException ("Member
type not allowed");
+ }
+
+ if (!type.IsAssignableFrom (args [i].Type))
+ throw new ArgumentException ("Argument
type not assignable to member type");
+ }
+
+ return new NewExpression (constructor, args, mmbs);
}
public static NewArrayExpression NewArrayBounds (Type type,
params Expression [] bounds)
Modified:
trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs
2008-02-19 13:52:05 UTC (rev 96145)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs
2008-02-19 14:11:37 UTC (rev 96146)
@@ -322,7 +322,16 @@
protected override void VisitNew (NewExpression nex)
{
Print ("new {0}(", nex.Type.Name);
- VisitExpressionList (nex.Arguments);
+ if (nex.Members != null && nex.Members.Count > 0) {
+ for (int i = 0; i < nex.Members.Count; i++) {
+ if (i > 0)
+ Print (ListSeparator);
+
+ Print ("{0} = ", nex.Members [i].Name);
+ Visit (nex.Arguments [i]);
+ }
+ } else
+ VisitExpressionList (nex.Arguments);
Print (")");
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches