public override Meta BindInvoke(InvokeBinder binder, Meta[] args) { return new Meta( Et.Call( EtUtils.Cast<IFunction>( this.Expression ), IFunctionMethods.MiCall, EtUtils.Cast<IObj>( args[0].Expression ), AstUtils.NewArrayHelper( typeof(object), DynamicUtils.GetExpressions( ArrayUtils.RemoveFirst(args) ) ) ), RestrictUtils.BuildCallRestrictions( this, args, RestrictFlag.Type ) ); }
internal DelegateInfo(LanguageContext context, Type returnType, ParameterInfo[] parameters) { Assert.NotNull(returnType); Assert.NotNullItems(parameters); _returnType = returnType; _parameters = parameters; PerfTrack.NoteEvent(PerfTrack.Categories.DelegateCreate, ToString()); if (_returnType != typeof(void)) { _convertBinder = context.CreateConvertBinder(_returnType, true); } _invokeBinder = context.CreateInvokeBinder(new CallInfo(_parameters.Length)); Type[] delegateParams = new Type[_parameters.Length]; for (int i = 0; i < _parameters.Length; i++) { delegateParams[i] = _parameters[i].ParameterType; } // Create the method with a special name so the langauge compiler knows that method's stack frame is not visible DynamicILGen cg = Snippets.Shared.CreateDynamicMethod("_Scripting_", _returnType, ArrayUtils.Insert(typeof(object[]), delegateParams), false); // Emit the stub _constants = EmitClrCallStub(cg); _method = cg.Finish(); }
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { output.Write(string.Format("Try invoke with {0} arguments {1} and return type is {2}", binder.CallInfo.ArgumentCount, string.Join(", ", binder.CallInfo.ArgumentNames), binder.ReturnType.FullName)); var res = baseElement.TryInvoke(binder, args, out result); return true; }
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { if (binder == null) throw new ArgumentNullException("binder"); if (Resource(args, out result)) return true; if (Query(args, out result)) return true; if (Extensions.IsHttpVerb(GetLastCall())) { result = HttpVerb(args); return true; } var builder = new StringBuilder(_callLog); foreach (var t in args) { builder.Append("/"); var s = t as string; if (s != null) builder.Append("@\"").Append(s.Replace("\"", "\"\"")).Append("\""); else builder.Append(t); } result = new MemberAccessWrapper(_httpClientWrapper, _baseUri, builder.ToString()); return true; }
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { Console.WriteLine("TryInvoke is called"); bool tryResult = base.TryInvoke(binder, args, out result); return true; }
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { var innerResult = _inner.TryInvoke(binder, args, out result); //special case, we need to check if the result is of a non-legacy dynamic type because if it is, we need //to return the legacy type result = LegacyConverter.ConvertToLegacy(result); return innerResult; }
public static ImmutableDictionary<string, object> ParseArgs(object[] args, InvokeBinder binder) { if (binder.CallInfo.ArgumentCount == 0) return Empty; if (binder.CallInfo.ArgumentCount == 1 && (binder.CallInfo.ArgumentNames.Count == 0 || string.IsNullOrWhiteSpace(binder.CallInfo.ArgumentNames[0]))) { return ObjectToDictionary(args[0]); } return ArgsToDictionary(args, binder); }
public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) { return new DynamicMetaObject( Expression.Call( Expression.Constant(Function), typeof(BonsaiFunction).GetMethod("Call"), Expression.NewArrayInit(typeof(object), args.Select(a => Expression.Convert(a.Expression, typeof(object))))), BindingRestrictions.GetInstanceRestriction(this.Expression, Function)); }
/// <summary> /// Tries to perform binding of the dynamic invoke operation. /// </summary> /// <param name="binder">An instance of the <see cref="GetMemberBinder"/> that represents the details of the dynamic operation.</param> /// <param name="instance">The target of the dynamic operation. </param> /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke member operation.</param> /// <param name="result">The new <see cref="DynamicMetaObject"/> representing the result of the binding.</param> /// <returns>true if operation was bound successfully; otherwise, false.</returns> public static bool TryBindInvoke(InvokeBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) { if (TryGetMetaObject(ref instance)) { result = instance.BindInvoke(binder, args); return true; } else { result = null; return false; } }
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { IodineObject[] arguments = new IodineObject[args.Length]; for (int i = 0; i < args.Length; i++) { arguments [i] = typeRegistry.ConvertToIodineObject (args [i]); } IodineObject returnVal = internalObject.Invoke (internalVm, arguments); result = typeRegistry.ConvertToNativeObject (returnVal); return true; }
/// <summary> /// Tries the invoke. /// </summary> /// <param name="binder">The binder.</param> /// <param name="args">The args.</param> /// <param name="result">The result.</param> /// <returns></returns> public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { result = null; if (args.Length == 1 && args.First() is String) { result = _lookup(args[0] as String); return true; } return false; }
/// <summary> /// Evaluates JavaScript directly within the context of the target object. /// Particularly useful for expressing lambdas, but can be used to execute any JavaScript that cannot be expressed in C#. /// </summary> /// <example> /// var visibleText = elements("filter(e => e.visible).map(e => e.textContent)"); /// </example> public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { try { var script = "this." + args.Single().ToString(); result = target.eval(script).Result; if (result is ExpandoObject) result = new Bridge(result); return true; } catch (AggregateException e) { throw e.InnerException; } }
public static DynamicMetaObject/*!*/ Bind(RubyContext/*!*/ context, InvokeBinder/*!*/ binder, RubyMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args, Action<MetaObjectBuilder, CallArguments>/*!*/ buildInvoke) { RubyCallSignature callSignature; if (RubyCallSignature.TryCreate(binder.CallInfo, out callSignature)) { return binder.FallbackInvoke(target, args); } var metaBuilder = new MetaObjectBuilder(); buildInvoke(metaBuilder, new CallArguments(target.CreateMetaContext(), target, args, callSignature)); return metaBuilder.CreateMetaObject(binder); }
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { result = null; if (args.Length > 0) { result = Evaluate(args[0].ToString()); args.Skip(1).Select(x => x.ToString()).ToList().ForEach(Execute); } return true; }
public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) { ContractUtils.RequiresNotNull(binder, "binder"); ComMethodDesc method; if (_self.TryGetGetItem(out method)) { bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref args); return BindComInvoke(args, method, binder.CallInfo, isByRef); } return base.BindInvoke(binder, args); }
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { if (!commands.Any()) { result = null; return true; } var runOptions = new RunOptions(this); result = Runner.Run(runOptions); return true; }
/// <summary> /// Provides the implementation for operations that invoke an object. Classes derived from the <see /// cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations such as invoking an object or a delegate. /// </summary> /// <param name="binder"> Provides information about the invoke operation. </param> /// <param name="args"> The arguments that are passed to the object during the invoke operation. For example, for the sampleObject(100) operation, where sampleObject is derived from the <see /// cref="T:System.Dynamic.DynamicObject" /> class, <paramref name="args" /> [0] is equal to 100. </param> /// <param name="result"> The result of the object invocation. </param> /// <returns> true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown. </returns> public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { var tCurrying = _target as Currying; result = tCurrying != null //If already currying append ? new Currying(tCurrying.Target, tCurrying.MemberName, tCurrying.Args.Concat(Util.NameArgsIfNecessary(binder.CallInfo, args)). ToArray(), tCurrying.TotalArgCount, tCurrying.InvocationKind) : new Currying(_target, String.Empty, Util.NameArgsIfNecessary(binder.CallInfo, args), _totalArgCount); return true; }
public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) { ContractUtils.RequiresNotNull(binder, "binder"); ComMethodDesc method; if (_self.TryGetGetItem(out method)) { IList<ArgumentInfo> argInfos = binder.Arguments; ComBinderHelpers.ProcessArgumentsForCom(ref args, ref argInfos); return BindComInvoke(args, method, argInfos); } return base.BindInvoke(binder, args); }
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { var names = binder.CallInfo.ArgumentNames; var numberOfArguments = binder.CallInfo.ArgumentCount; var numberOfNames = names.Count; var allNames = Enumerable.Repeat<string>(null, numberOfArguments - numberOfNames).Concat(names); arguments.AddRange(allNames.Zip(args, (flag, value) => new Argument(flag, value))); var runOptions = new RunOptions(this); result = Runner.Run(runOptions); return true; }
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { if (args.Length > 0) { result = val + args[0]; } else { result = new Goal(val + "o"); } return true; }
/// <summary> /// Provides the implementation for operations that invoke an object. Classes derived from the <see /// cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations such as invoking an object or a delegate. /// </summary> /// <param name="binder"> Provides information about the invoke operation. </param> /// <param name="args"> The arguments that are passed to the object during the invoke operation. For example, for the sampleObject(100) operation, where sampleObject is derived from the <see /// cref="T:System.Dynamic.DynamicObject" /> class, <paramref name="args" /> [0] is equal to 100. </param> /// <param name="result"> The result of the object invocation. </param> /// <returns> true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown. </returns> public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { IEnumerable<KeyValuePair<string, object>> tDict = null; object target = null; result = null; //Setup Properties as dictionary if (binder.CallInfo.ArgumentNames.Any()) { if (binder.CallInfo.ArgumentNames.Count + 1 == binder.CallInfo.ArgumentCount) { target = args.First(); tDict = binder.CallInfo.ArgumentNames .Zip(args.Skip(1), (key, value) => new {key, value}) .ToDictionary(k => k.key, v => v.value); } else { throw new RuntimeBinderException("InvokeSetAll requires first parameter to be target unamed, and all other parameters to be named."); } } else if (args.Length == 2) { target = args[0]; if (args[1] is IEnumerable<KeyValuePair<string, object>>) { tDict = (IEnumerable<KeyValuePair<string, object>>)args[1]; } else if (args[1] is IEnumerable && args[1].GetType().IsGenericType ) { var tEnumerableArg = (IEnumerable)args[1]; var tInterface = tEnumerableArg.GetType().GetInterface("IEnumerable`1", false); if (tInterface != null) { var tParamTypes = tInterface.GetGenericArguments(); if (tParamTypes.Length == 1 && tParamTypes[0].GetGenericTypeDefinition() == typeof (Tuple<,>)) { tDict = tEnumerableArg.Cast<dynamic>().ToDictionary(k => (string)k.Item1, v => (object)v.Item2); } } } else if (Util.IsAnonymousType(args[1])) { var keyDict = new Dictionary<string, object>(); foreach (var tProp in args[1].GetType().GetProperties()) { keyDict[tProp.Name] = Impromptu.InvokeGet(args[1], tProp.Name); } tDict = keyDict; } } //Invoke all properties if (target != null && tDict != null) { foreach (var tPair in tDict) { Impromptu.InvokeSetChain(target, tPair.Key, tPair.Value); } result = target; return true; } return false; }
internal DelegateSignatureInfo(LanguageContext context, Type returnType, ParameterInfo[] parameters) { Assert.NotNull(context, returnType); Assert.NotNullItems(parameters); _context = context; _parameters = parameters; _returnType = returnType; if (_returnType != typeof(void)) { _convert = _context.CreateConvertBinder(_returnType, true); } _invoke = _context.CreateInvokeBinder(new CallInfo(_parameters.Length)); }
public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) { ContractUtils.RequiresNotNull(binder, "binder"); if (args.Any(arg => ComBinderHelpers.IsStrongBoxArg(arg))) { return ComBinderHelpers.RewriteStrongBoxAsRef(binder, this, args, false); } ComMethodDesc method; if (_self.TryGetGetItem(out method)){ return BindComInvoke(args, method, binder.Arguments); } return base.BindInvoke(binder, args); }
public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) { ComMethodDesc method; if (_self.TryGetGetItem(out method)) { List<ParameterExpression> temps = new List<ParameterExpression>(); List<Expression> initTemps = new List<Expression>(); bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(method, ref args, temps, initTemps); return BindComInvoke(args, method, binder.CallInfo, isByRef, temps, initTemps); } return base.BindInvoke(binder, args); }
/// <summary> /// Provides the implementation for operations that invoke an object. Classes derived from the <see cref="T:System.Dynamic.DynamicObject"/> class can override this method to specify dynamic behavior for operations such as invoking an object or a delegate. /// </summary> /// <param name="binder">Provides information about the invoke operation.</param> /// <param name="args">The arguments that are passed to the object during the invoke operation. For example, for the sampleObject(100) operation, where sampleObject is derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, <paramref name="args"/>[0] is equal to 100.</param> /// <param name="result">The result of the object invocation.</param> /// <returns> /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown. /// </returns> public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { var tCurrying = _target as PartialApplyInvocation; var curryResult = tCurrying != null //If already currying append ? new PartialApplyInvocation(tCurrying.Target, tCurrying.Args.Concat(Util.NameArgsIfNecessary(binder.CallInfo, args)). ToArray(), tCurrying.MemberName, tCurrying.TotalArgCount, tCurrying.InvocationKind) : new PartialApplyInvocation(_target, Util.NameArgsIfNecessary(binder.CallInfo, args), String.Empty, _totalArgCount); result = curryResult; if (args.Length == curryResult.TotalArgCount) result = ((dynamic)curryResult)(); return true; }
public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ action, DynamicMetaObject/*!*/[]/*!*/ args) { RubyCallSignature callSignature; if (RubyCallSignature.TryCreate(action.Arguments, out callSignature)) { return action.FallbackInvoke(this, args); } var metaBuilder = new MetaObjectBuilder(); var context = new DynamicMetaObject( Methods.GetContextFromBlockParam.OpCall(AstUtils.Convert(Expression, typeof(BlockParam))), BindingRestrictions.Empty, RubyOps.GetContextFromBlockParam((BlockParam)Value) ); BlockParam.SetCallActionRule(metaBuilder, new CallArguments(context, this, args, callSignature)); return metaBuilder.CreateMetaObject(action, args); }
public static IExpression Parse(Table table, object[] args, InvokeBinder binder) { if (args.Length == 1) { var expression = args[0] as IExpression; if (expression != null) return expression; } var dict = ReadBinder.ParseArgs(args, binder); var kvp = dict.FirstOrDefault(); var column = new Column(kvp.Key, table); if (kvp.Value is FloatingOperand) { return ((FloatingOperand) kvp.Value).GetExpression(column); } return SimpleExpression.Equal(column, kvp.Value); }
public override MetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ action, MetaObject/*!*/[]/*!*/ args) { RubyCallSignature callSignature; if (RubyCallSignature.TryCreate(action.Arguments, out callSignature)) { return action.FallbackInvoke(this, args); } var self = (RubyMethod)Value; var context = new MetaObject( Methods.GetContextFromMethod.OpCall(AstUtils.Convert(Expression, typeof(RubyMethod))), Restrictions.Empty, RubyOps.GetContextFromMethod(self) ); var metaBuilder = new MetaObjectBuilder(); Method.SetRuleForCall(metaBuilder, new CallArguments(context, this, args, callSignature)); return metaBuilder.CreateMetaObject(action, args); }
internal DelegateSignatureInfo(LanguageContext context, Type returnType, ParameterInfo[] parameters) { Assert.NotNull(context, returnType); Assert.NotNullItems(parameters); _context = context; _parameters = parameters; _returnType = returnType; if (_returnType != typeof(void)) { _convert = _context.CreateConvertBinder(_returnType, true); } ArgumentInfo[] args = new ArgumentInfo[_parameters.Length]; for (int i = 0; i < args.Length; i++) { args[i] = Expression.PositionalArg(i); } _invoke = _context.CreateInvokeBinder(args); }
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { IodineObject[] arguments = new IodineObject[args.Length]; for (int i = 0; i < args.Length; i++) { IodineObject val = null; if (!IodineTypeConverter.Instance.ConvertFromPrimative (args [i], out val)) { if (args [i] is IodineObject) { val = (IodineObject)args [i]; } else { result = null; return false; } } arguments [i] = val; } IodineObject returnVal = internalObject.Invoke (internalVm, arguments); if (!IodineTypeConverter.Instance.ConvertToPrimative (returnVal, out result)) { result = new IodineDynamicObject (returnVal, internalVm); } return true; }
public virtual new bool TryInvoke(InvokeBinder binder, Object[] args, out Object result) { result = default(Object); return(default(bool)); }
public virtual DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) { throw new NotImplementedException(); }
// // Summary: // Provides the implementation for operations that invoke an object. Classes derived // from the System.Dynamic.DynamicObject class can override this method to specify // dynamic behavior for operations such as invoking an object or a delegate. // // Parameters: // binder: // Provides information about the invoke operation. // // args: // The arguments that are passed to the object during the invoke operation. For // example, for the sampleObject(100) operation, where sampleObject is derived from // the System.Dynamic.DynamicObject class, args[0] is equal to 100. // // result: // The result of the object invocation. // // Returns: // true if the operation is successful; otherwise, false. If this method returns // false, the run-time binder of the language determines the behavior. (In most // cases, a language-specific run-time exception is thrown. public virtual bool TryInvoke(InvokeBinder binder, object[] args, out object result);
public virtual bool TryInvoke(InvokeBinder binder, object[] args, ref object result) { throw new NotImplementedException(); }
/// <summary> /// Performs the binding of the dynamic invoke operation. /// </summary> /// <param name="binder">An instance of the <see cref="InvokeBinder"/> that represents the details of the dynamic operation.</param> /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke operation.</param> /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns> public virtual DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) { ArgumentNullException.ThrowIfNull(binder); return(binder.FallbackInvoke(this, args)); }
/// <summary> /// Performs the binding of the dynamic invoke operation. /// </summary> /// <param name="binder">An instance of the <see cref="InvokeBinder"/> that represents the details of the dynamic operation.</param> /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke operation.</param> /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns> public virtual DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) { ContractUtils.RequiresNotNull(binder, nameof(binder)); return(binder.FallbackInvoke(this, args)); }
public virtual bool TryInvoke(InvokeBinder binder, object[] args, out object result) { result = null; return(false); }
public virtual new System.Dynamic.DynamicMetaObject BindInvoke(InvokeBinder binder, System.Dynamic.DynamicMetaObject[] args) { Contract.Requires(binder != null); return(default(System.Dynamic.DynamicMetaObject)); }