Author: jbevain
Date: 2008-02-20 14:25:03 -0500 (Wed, 20 Feb 2008)
New Revision: 96293

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-20  Jb Evain  <[EMAIL PROTECTED]>

        * Expression.cs, ExpressionPrinter.cs: implement MemberBind.



Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog       
2008-02-20 19:20:24 UTC (rev 96292)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog       
2008-02-20 19:25:03 UTC (rev 96293)
@@ -1,5 +1,9 @@
 2008-02-20  Jb Evain  <[EMAIL PROTECTED]>
 
+       * Expression.cs, ExpressionPrinter.cs: implement MemberBind.
+
+2008-02-20  Jb Evain  <[EMAIL PROTECTED]>
+
        * Expression.cs, ExpressionPrinter.cs: implement ListInit.
 
 2008-02-19  Jb Evain  <[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-20 19:20:24 UTC (rev 96292)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs   
2008-02-20 19:25:03 UTC (rev 96293)
@@ -1460,39 +1460,53 @@
                        throw new ArgumentException ("MakeUnary expect an unary 
operator");
                }
 
-               [MonoTODO]
-               public static MemberMemberBinding MemberBind (MemberInfo 
member, params MemberBinding [] binding)
+               public static MemberMemberBinding MemberBind (MemberInfo 
member, params MemberBinding [] bindings)
                {
-                       throw new NotImplementedException ();
+                       return MemberBind (member, bindings as 
IEnumerable<MemberBinding>);
                }
 
-               [MonoTODO]
-               public static MemberMemberBinding MemberBind (MemberInfo 
member, IEnumerable<MemberBinding> binding)
+               public static MemberMemberBinding MemberBind (MemberInfo 
member, IEnumerable<MemberBinding> bindings)
                {
-                       throw new NotImplementedException ();
+                       if (member == null)
+                               throw new ArgumentNullException ("member");
+
+                       Type type = null;
+                       switch (member.MemberType) {
+                       case MemberTypes.Field:
+                               type = (member as FieldInfo).FieldType;
+                               break;
+                       case MemberTypes.Property:
+                               type = (member as PropertyInfo).PropertyType;
+                               break;
+                       default:
+                               throw new ArgumentException ("Member is neither 
a field or a property");
+                       }
+
+                       return new MemberMemberBinding (member, 
CheckMemberBindings (type, bindings));
                }
 
-               [MonoTODO]
-               public static MemberMemberBinding MemberBind (MethodInfo 
propertyAccessor, params MemberBinding [] binding)
+               public static MemberMemberBinding MemberBind (MethodInfo 
propertyAccessor, params MemberBinding [] bindings)
                {
-                       throw new NotImplementedException ();
+                       return MemberBind (propertyAccessor, bindings as 
IEnumerable<MemberBinding>);
                }
 
-               [MonoTODO]
-               public static MemberMemberBinding MemberBind (MethodInfo 
propertyAccessor, IEnumerable<MemberBinding> binding)
+               public static MemberMemberBinding MemberBind (MethodInfo 
propertyAccessor, IEnumerable<MemberBinding> bindings)
                {
-                       throw new NotImplementedException ();
-               }
+                       if (propertyAccessor == null)
+                               throw new ArgumentNullException 
("propertyAccessor");
 
-               public static MemberInitExpression MemberInit (NewExpression 
newExpression, params MemberBinding [] bindings)
-               {
-                       return MemberInit (newExpression, bindings as 
IEnumerable<MemberBinding>);
+                       var bds = bindings.ToReadOnlyCollection ();
+                       CheckForNull (bds, "bindings");
+
+                       var prop = GetAssociatedProperty (propertyAccessor);
+                       if (prop == null)
+                               throw new ArgumentException 
("propertyAccessor");
+
+                       return new MemberMemberBinding (prop, 
CheckMemberBindings (prop.PropertyType, bindings));
                }
 
-               public static MemberInitExpression MemberInit (NewExpression 
newExpression, IEnumerable<MemberBinding> bindings)
+               static ReadOnlyCollection<MemberBinding> CheckMemberBindings 
(Type type, IEnumerable<MemberBinding> bindings)
                {
-                       if (newExpression == null)
-                               throw new ArgumentNullException 
("newExpression");
                        if (bindings == null)
                                throw new ArgumentNullException ("bindings");
 
@@ -1500,12 +1514,25 @@
                        CheckForNull (bds, "bindings");
 
                        foreach (var binding in bds)
-                               if 
(!binding.Member.DeclaringType.IsAssignableFrom (newExpression.Type))
-                                       throw new ArgumentException 
("Expression type not assignable to member type");
+                               if 
(!binding.Member.DeclaringType.IsAssignableFrom (type))
+                                       throw new ArgumentException ("Type not 
assignable to member type");
 
-                       return new MemberInitExpression (newExpression, bds);
+                       return bds;
                }
 
+               public static MemberInitExpression MemberInit (NewExpression 
newExpression, params MemberBinding [] bindings)
+               {
+                       return MemberInit (newExpression, bindings as 
IEnumerable<MemberBinding>);
+               }
+
+               public static MemberInitExpression MemberInit (NewExpression 
newExpression, IEnumerable<MemberBinding> bindings)
+               {
+                       if (newExpression == null)
+                               throw new ArgumentNullException 
("newExpression");
+
+                       return new MemberInitExpression (newExpression, 
CheckMemberBindings (newExpression.Type, bindings));
+               }
+
                public static UnaryExpression Negate (Expression expression)
                {
                        return Negate (expression, null);

Modified: 
trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs    
2008-02-20 19:20:24 UTC (rev 96292)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ExpressionPrinter.cs    
2008-02-20 19:25:03 UTC (rev 96293)
@@ -281,7 +281,11 @@
 
                protected override void VisitMemberMemberBinding 
(MemberMemberBinding binding)
                {
-                       throw new NotImplementedException ();
+                       Print (binding.Member.Name);
+                       Print (" = {");
+                       // VisitBindingList (binding.Bindings);
+                       VisitList (binding.Bindings, VisitBinding);
+                       Print ("}");
                }
 
                protected override void VisitMemberListBinding 
(MemberListBinding binding)

_______________________________________________
Mono-patches maillist  -  Mono-patches@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to