Add EntityFramework (not same as System.Data.Entity)
[mono.git] / mcs / class / Microsoft.CSharp / Microsoft.CSharp.RuntimeBinder / CSharpGetIndexBinder.cs
index 164dd6a4a3bf7424295fdd9d946b9eb4aa9f7369..367cc22b70e1a63c50a50fc53a577e506f153cf3 100644 (file)
@@ -30,49 +30,42 @@ using System;
 using System.Dynamic;
 using System.Collections.Generic;
 using System.Linq;
+using Compiler = Mono.CSharp;
 
 namespace Microsoft.CSharp.RuntimeBinder
 {
-       public class CSharpGetIndexBinder : GetIndexBinder
+       class CSharpGetIndexBinder : GetIndexBinder
        {
                IList<CSharpArgumentInfo> argumentInfo;
                Type callingContext;
                
                public CSharpGetIndexBinder (Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
-                       : base (argumentInfo.ToCallInfo ())
+                       : base (CSharpArgumentInfo.CreateCallInfo (argumentInfo, 1))
                {
                        this.callingContext = callingContext;
                        this.argumentInfo = argumentInfo.ToReadOnly ();
                }
-               
-               public IList<CSharpArgumentInfo> ArgumentInfo {
-                       get {
-                               return argumentInfo;
-                       }
-               }
+                       
+               public override DynamicMetaObject FallbackGetIndex (DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion)
+               {
+                       if (argumentInfo.Count != indexes.Length + 1) {
+                               if (errorSuggestion == null)
+                                       throw new NotImplementedException ();
 
-               public Type CallingContext {
-                       get {
-                               return callingContext;
+                               return errorSuggestion;
                        }
-               }
-               
-               public override bool Equals (object obj)
-               {
-                       var other = obj as CSharpGetIndexBinder;
-                       return other != null && base.Equals (obj) && other.callingContext == callingContext && 
-                               other.argumentInfo.SequenceEqual (argumentInfo);
-               }
 
-               public override int GetHashCode ()
-               {
-                       return base.GetHashCode ();
-               }
-               
-               [MonoTODO]
-               public override DynamicMetaObject FallbackGetIndex (DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion)
-               {
-                       throw new NotImplementedException ();
+                       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);
+                       expr = new Compiler.Cast (new Compiler.TypeExpression (ctx.ImportType (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null);
+
+                       var binder = new CSharpBinder (this, expr, errorSuggestion);
+                       binder.AddRestrictions (target);
+                       binder.AddRestrictions (indexes);
+
+                       return binder.Bind (ctx, callingContext);
                }
        }
 }