public object Evaluate(object left, object right) { if (left == null || right == null) { return(object.Equals(left, right)); } IObjectBind equalityMethod = null; equalityMethod = RuntimeHost.Binder.BindToMethod(left, "op_Equality", null, new object[] { left, right }); if (equalityMethod != null) { return(equalityMethod.Invoke(null, new object[] { left, right })); } equalityMethod = RuntimeHost.Binder.BindToMethod(right, "op_Equality", null, new object[] { right, left }); if (equalityMethod != null) { return(equalityMethod.Invoke(null, new object[] { right, left })); } equalityMethod = RuntimeHost.Binder.BindToMethod(left, "Equals", null, new object[] { right }); if (equalityMethod != null) { return(equalityMethod.Invoke(null, new object[] { left, right })); } return(object.Equals(left, right)); }
public virtual object Invoke(IScriptContext context, object[] args) { object result = RuntimeHost.NullValue; IObjectBind bind = null; if (MethodInfo == null) { bind = RuntimeHost.Binder.BindToMethod(Target, MethodName, null, args); } else { bind = RuntimeHost.Binder.BindToMethod(Target, MethodInfo, args); } if (bind != null) { result = bind.Invoke(context, null); } else { throw new ScriptMethodNotFoundException(MethodName); } context.Result = result; return(result); }
public object Invoke(IScriptContext context, object[] args) { context.CreateScope(); context.SetItem("me", scriptable.Instance); context.SetItem("body", scriptable); object rez = RuntimeHost.NullValue; try { rez = dynamicMethod.Invoke(context, arguments); } finally { context.RemoveLocalScope(); } if (rez != RuntimeHost.NullValue) { return(rez); } else { throw new ScriptException(string.Format("Dynamic method call failed in object {0}", scriptable.ToString())); } }
public object GetValue() { if (getter == null) { throw new NotSupportedException(); } return(getter.Invoke(null, new object[0])); }
public void SetValue(object value) { if (setter == null) { throw new NotSupportedException(); } setter.Invoke(null, new object[] { value }); }
private static object CallAppropriateMethod(IScriptContext context, object obj, string Name, Type[] genericArguments, object[] param) { IObjectBind methodBind = methodBind = RuntimeHost.Binder.BindToMethod(obj, Name, genericArguments, param); if (methodBind != null) { return(methodBind.Invoke(context, null)); } throw MethodNotFoundException(Name, param); }
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); }
public override void Evaluate(IScriptContext context) { expr.Evaluate(context); IEnumerable enumeration = context.Result as IEnumerable; IEnumerator enumerator = null; if (enumeration != null) { enumerator = enumeration.GetEnumerator(); } else { IObjectBind bind = RuntimeHost.Binder.BindToMethod(context.Result, "GetEnumerator", new Type[0], new object[0]); if (bind != null) { enumerator = bind.Invoke(context, null) as IEnumerator; } } if (enumerator == null) { throw new ScriptException("GetEnumerator() method did not found in object: " + context.Result.ToString()); } enumerator.Reset(); while (enumerator.MoveNext()) { context.SetItem(name.Text, enumerator.Current); statement.Evaluate(context); if (context.IsBreak() || context.IsReturn()) { context.SetBreak(false); break; } if (context.IsContinue()) { context.SetContinue(false); } } }
public object CreateInstance(IScriptContext context, IObjectBind bind) { return bind.Invoke(context, null); }
public object CreateInstance(IScriptContext context, IObjectBind bind) { return(bind.Invoke(context, null)); }