Author: jbevain
Date: 2008-01-28 18:02:26 -0500 (Mon, 28 Jan 2008)
New Revision: 94190
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/NewExpression.cs
Log:
2008-01-29 Jb Evain <[EMAIL PROTECTED]>
* Expression.cs, NewExpression.cs, ExpressionPrinter.cs:
implement the first flavors of New.
Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
2008-01-28 22:55:05 UTC (rev 94189)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
2008-01-28 23:02:26 UTC (rev 94190)
@@ -1,3 +1,8 @@
+2008-01-29 Jb Evain <[EMAIL PROTECTED]>
+
+ * Expression.cs, NewExpression.cs, ExpressionPrinter.cs:
+ implement the first flavors of New.
+
2008-01-27 Jb Evain <[EMAIL PROTECTED]>
* ConditionalExpression.cs: implement Emit.
Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
2008-01-28 22:55:05 UTC (rev 94189)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
2008-01-28 23:02:26 UTC (rev 94190)
@@ -1346,28 +1346,53 @@
return MakeSimpleUnary (ExpressionType.Negate,
expression, method);
}
- [MonoTODO]
public static NewExpression New (ConstructorInfo constructor)
{
- throw new NotImplementedException ();
+ if (constructor == null)
+ throw new ArgumentNullException ("constructor");
+
+ if (constructor.GetParameters ().Length > 0)
+ throw new ArgumentException ("Constructor must
be parameter less");
+
+ return new NewExpression (constructor, (null as
IEnumerable<Expression>).ToReadOnlyCollection<Expression> (), null);
}
- [MonoTODO]
public static NewExpression New (Type type)
{
- throw new NotImplementedException ();
+ if (type == null)
+ throw new ArgumentNullException ("type");
+
+ if (type.GetConstructor (Type.EmptyTypes) == null)
+ throw new ArgumentException ("Type doesn't have
a parameter less constructor");
+
+ return new NewExpression (type, (null as
IEnumerable<Expression>).ToReadOnlyCollection<Expression> ());
}
- [MonoTODO]
public static NewExpression New (ConstructorInfo constructor,
params Expression [] arguments)
{
- throw new NotImplementedException ();
+ return New (constructor, arguments as
IEnumerable<Expression>);
}
- [MonoTODO]
public static NewExpression New (ConstructorInfo constructor,
IEnumerable<Expression> arguments)
{
- throw new NotImplementedException ();
+ if (constructor == null)
+ throw new ArgumentNullException ("constructor");
+
+ var args = arguments.ToReadOnlyCollection ();
+ var parameters = constructor.GetParameters ();
+
+ if (args.Count != parameters.Length)
+ throw new ArgumentException ("arguments");
+
+ for (int i = 0; i < parameters.Length; i++) {
+ if (args [i] == null)
+ throw new ArgumentNullException
("arguments");
+
+ if (!parameters
[i].ParameterType.IsAssignableFrom (args [i].Type))
+ throw new ArgumentException
("arguments");
+ }
+
+ return new NewExpression (constructor, args, null);
}
[MonoTODO]
Modified:
trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs
2008-01-28 22:55:05 UTC (rev 94189)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs
2008-01-28 23:02:26 UTC (rev 94190)
@@ -311,7 +311,9 @@
protected override void VisitNew (NewExpression nex)
{
- throw new NotImplementedException ();
+ Print ("new {0}(", nex.Type.Name);
+ VisitExpressionList (nex.Arguments);
+ Print (")");
}
protected override void VisitMemberInit (MemberInitExpression
init)
Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/NewExpression.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/NewExpression.cs
2008-01-28 22:55:05 UTC (rev 94189)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/NewExpression.cs
2008-01-28 23:02:26 UTC (rev 94190)
@@ -49,8 +49,14 @@
public ReadOnlyCollection<MemberInfo> Members {
get { return members; }
}
-
- internal NewExpression (ConstructorInfo constructor,
ReadOnlyCollection<Expression> arguments, ReadOnlyCollection<MemberInfo>
members)
+
+ internal NewExpression (Type type,
ReadOnlyCollection<Expression> arguments)
+ : base (ExpressionType.New, type)
+ {
+ this.arguments = arguments;
+ }
+
+ internal NewExpression (ConstructorInfo constructor,
ReadOnlyCollection<Expression> arguments, ReadOnlyCollection<MemberInfo>
members)
: base (ExpressionType.New, constructor.DeclaringType)
{
this.constructor = constructor;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches