//TODO: Refactor public override void Evaluate(IScriptContext context) { constrExpr.Evaluate(context); Type type = (Type)context.Result; arrRank.Evaluate(context); int rank = (int)Convert.ChangeType(((object[])context.Result)[0], typeof(int), CultureInfo.CurrentCulture.NumberFormat); context.Result = Array.CreateInstance(type, rank); }
private static void GetArrayValue(object obj, ScriptArrayResolution scriptArrayResolution, IScriptContext context) { scriptArrayResolution.Evaluate(context); object[] param = (object[])context.Result; IObjectBind indexBind = RuntimeHost.Binder.BindToIndex(obj, param, false); if (indexBind != null) { context.Result = indexBind.Invoke(context, null); } else { throw MethodNotFoundException("indexer[]", param); } }
private static void SetArrayValue(object obj, ScriptArrayResolution scriptArrayResolution, IScriptContext context, object value) { scriptArrayResolution.Evaluate(context); object[] indexParameters = (object[])context.Result; object[] setterParameters = new object[indexParameters.Length + 1]; indexParameters.CopyTo(setterParameters, 0); setterParameters[indexParameters.Length] = value; IObjectBind setter = RuntimeHost.Binder.BindToIndex(obj, setterParameters, true); if (setter != null) { setter.Invoke(context, null); return; } throw MethodNotFoundException("setter", indexParameters); }