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;
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);
}
}
}