[msbuild] Getting build error "Error initializing task XmlPeek: Not registered task...
[mono.git] / mcs / class / Microsoft.CSharp / Microsoft.CSharp.RuntimeBinder / CSharpSetIndexBinder.cs
index 70f7457193036e0bc79d04dffb6de06391ce8e81..ad2f51a1dbf85f2c62ffa6d9149fbf00a133694d 100644 (file)
@@ -30,49 +30,57 @@ using System;
 using System.Dynamic;
 using System.Collections.Generic;
 using System.Linq;
+using Compiler = Mono.CSharp;
 
 namespace Microsoft.CSharp.RuntimeBinder
 {
-       public class CSharpSetIndexBinder : SetIndexBinder
+       class CSharpSetIndexBinder : SetIndexBinder
        {
+               readonly CSharpBinderFlags flags;
                IList<CSharpArgumentInfo> argumentInfo;
                Type callingContext;
-               
-               public CSharpSetIndexBinder (Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
+
+               public CSharpSetIndexBinder (CSharpBinderFlags flags, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
                        : base (CSharpArgumentInfo.CreateCallInfo (argumentInfo, 2))
                {
+                       this.flags = flags;
                        this.callingContext = callingContext;
                        this.argumentInfo = argumentInfo.ToReadOnly ();
                }
                
-               public IList<CSharpArgumentInfo> ArgumentInfo {
-                       get {
-                               return argumentInfo;
+               public override DynamicMetaObject FallbackSetIndex (DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
+               {
+                       if (argumentInfo.Count != indexes.Length + 2) {
+                               if (errorSuggestion == null)
+                                       throw new NotImplementedException ();
+
+                               return errorSuggestion;
                        }
-               }
 
-               public Type CallingContext {
-                       get {
-                               return callingContext;
+                       var ctx = DynamicContext.Create ();
+                       var expr = ctx.CreateCompilerExpression (argumentInfo [0], target);
+                       var args = ctx.CreateCompilerArguments (argumentInfo.Skip (1), indexes);
+                       expr = new Compiler.ElementAccess (expr, args, Compiler.Location.Null);
+
+                       var source = ctx.CreateCompilerExpression (argumentInfo [indexes.Length + 1], value);
+
+                       // Same conversion as in SetMemberBinder
+                       if ((flags & CSharpBinderFlags.ValueFromCompoundAssignment) != 0) {
+                               expr = new Compiler.RuntimeExplicitAssign (expr, source);
+                       } else {
+                               expr = new Compiler.SimpleAssign (expr, source);
                        }
-               }
-               
-               public override bool Equals (object obj)
-               {
-                       var other = obj as CSharpSetIndexBinder;
-                       return other != null && base.Equals (obj) && other.callingContext == callingContext && 
-                               other.argumentInfo.SequenceEqual (argumentInfo);
-               }
+                       expr = new Compiler.Cast (new Compiler.TypeExpression (ctx.ImportType (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null);
 
-               public override int GetHashCode ()
-               {
-                       return base.GetHashCode ();
-               }
-               
-               [MonoTODO]
-               public override DynamicMetaObject FallbackSetIndex (DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
-               {
-                       throw new NotImplementedException ();
+                       if ((flags & CSharpBinderFlags.CheckedContext) != 0)
+                               expr = new Compiler.CheckedExpr (expr, Compiler.Location.Null);
+
+                       var binder = new CSharpBinder (this, expr, errorSuggestion);
+                       binder.AddRestrictions (target);
+                       binder.AddRestrictions (value);
+                       binder.AddRestrictions (indexes);
+
+                       return binder.Bind (ctx, callingContext);
                }
        }
 }