Beispiel #1
0
 public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
 {
     if (_memberdic.ContainsKey(binder.Name) && _memberdic[binder.Name] is Delegate)
     {
         result = (_memberdic[binder.Name] as Delegate).DynamicInvoke(args);
         return(true);
     }
     else
     {
         bool v = base.TryInvokeMember(binder, args, out result);
         return(v);
     }
 }
 public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
 {
     if ("Set".Equals(binder.Name, StringComparison.OrdinalIgnoreCase) && binder.CallInfo.ArgumentCount == 2)
     {
         string name = string.Concat(args[0]);
         if (string.IsNullOrEmpty(name))
         {
             result = null;
             return(false);
         }
         object value = args[1];
         objMapping.TryAdd(name, value);
         result = value;
         return(true);
     }
     return(base.TryInvokeMember(binder, args, out result));
 }
Beispiel #4
0
        /// <summary>
        /// Provides the implementation for operations that invoke a member. Classes derived from the <see cref="T:System.Dynamic.DynamicObject"/> class can override this method to specify dynamic behavior for operations such as calling a method.
        /// </summary>
        /// <param name="binder">Provides information about the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, binder.Name returns "SampleMethod". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
        /// <param name="args">The arguments that are passed to the object member during the invoke operation. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, <paramref name="args"/> is equal to 100.</param>
        /// <param name="result">The result of the member 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 TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
        {
            if (!base.TryInvokeMember(binder, args, out result))
            {
                try
                {
                    //Check if there is a get property because it might return a function
                    result = Dynamic.InvokeGet(this.CallTarget, binder.Name);
                }
                catch (RuntimeBinderException)
                {
                    return(false);
                }
                if (result == null)
                {
                    return(false);
                }
                var tDel = result as Delegate;
                if (!binder.CallInfo.ArgumentNames.Any() && tDel != null)
                {
                    try
                    {
                        result = this.InvokeMethodDelegate(tDel, args);
                    }
                    catch (RuntimeBinderException)
                    //If it has out parmaters etc it can't be invoked dynamically like this.
                    //if we return false it will be handle by the GetProperty and then handled by the original dynamic invocation
                    {
                        return(false);
                    }
                }
                try
                {
                    result = Dynamic.Invoke(result, Util.NameArgsIfNecessary(binder.CallInfo, args));
                }
                catch (RuntimeBinderException)//If it has out parmaters etc it can't be invoked dynamically like this.
                //if we return false it will be handle by the GetProperty and then handled by the original dynamic invocation
                {
                    return(false);
                }
            }

            return(this.MassageResultBasedOnInterface(binder.Name, true, ref result));
        }
Beispiel #5
0
 public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
 {
     System.Diagnostics.Debug.WriteLine("Enter: ", binder.Name);
     try
     {
         result = _innerType.InvokeMember(
             binder.Name,
             BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod,
             null, _innerObject, args);
     }
     catch (MissingMemberException)
     {
         return(base.TryInvokeMember(binder, args, out result));
     }
     finally
     {
         System.Diagnostics.Debug.WriteLine("Exit: ", binder.Name);
     }
     return(true);
 }
        public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
        {
            if (base.TryInvokeMember(binder, args, out result))
            {
                return(true);
            }

            var dataStrategy = _argument.FindDataStrategyInHierarchy();

            if (dataStrategy != null)
            {
                if (dataStrategy.IsExpressionFunction(binder.Name, args))
                {
                    result = new SimpleExpression(this, new SimpleFunction(binder.Name, args), SimpleExpressionType.Function);
                }
                else
                {
                    result = new FunctionReference(binder.Name, this, args);
                }
                return(true);
            }

            return(false);
        }
 public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
 {
     result = Create(binder.Name, Arguments.From(args, binder.CallInfo.ArgumentNames));
     return(true);
 }
 public virtual bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
 {
     throw null;
 }
 public virtual System.Dynamic.DynamicMetaObject BindInvokeMember(System.Dynamic.InvokeMemberBinder binder, System.Dynamic.DynamicMetaObject[] args)
 {
     throw null;
 }
 /// <summary>
 /// Provides the implementation for operations that invoke a member.
 /// </summary>
 /// <param name="binder"> Provides information about the dynamic operation. </param>
 /// <param name="args"> The arguments that are passed to the object member during the
 /// invoke operation. </param>
 /// <param name="result"> The result of the member invocation. </param>
 /// <returns> <c>true</c> if the operation is successful; otherwise, <c>false</c>. </returns>
 public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
 {
     return(this.obj.TryCallMemberFunction(out result, binder.Name, args));
 }
Beispiel #11
0
 /// <summary>
 /// Provides the implementation for operations that invoke a member. Classes derived from the <see cref="T:System.Dynamic.DynamicObject"/> class can override this method to specify dynamic behavior for operations such as calling a method.
 /// </summary>
 /// <param name="binder">Provides information about the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, binder.Name returns "SampleMethod". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
 /// <param name="args">The arguments that are passed to the object member during the invoke operation. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, <paramref name="args"/> is equal to 100.</param>
 /// <param name="result">The result of the member 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 TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
 {
     result = null;
     return(this.MassageResultBasedOnInterface(binder.Name, true, ref result));
 }
Beispiel #12
0
 /// <summary>
 /// Provides the implementation for operations that invoke a member. Classes derived from the <see cref="T:System.Dynamic.DynamicObject"/> class can override this method to specify dynamic behavior for operations such as calling a method.
 /// </summary>
 /// <param name="binder">Provides information about the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, binder.Name returns "SampleMethod". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
 /// <param name="args">The arguments that are passed to the object member during the invoke operation. For example, for the statement sampleObject.SampleMethod(100), 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 member 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 TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
 {
     result = GetInstanceForDynamicMember(binder.Name, args);
     return(result != null);
 }
 public virtual bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
 {
     result = default(object); return(default(bool));
 }
 public virtual System.Dynamic.DynamicMetaObject BindInvokeMember(System.Dynamic.InvokeMemberBinder binder, System.Dynamic.DynamicMetaObject[] args)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Beispiel #15
0
 public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
 {
     return(base.TryInvokeMember(binder, args, out result));
 }
        public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, Object[] args, out Object result)
        {
            result = default(Object);

            return(default(bool));
        }
Beispiel #17
0
        /// <summary>
        /// Provides the implementation for operations that invoke a member. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations such as calling a method.
        /// </summary>
        /// <param name="binder">Provides information about the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, binder.Name returns "SampleMethod". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
        /// <param name="args">The arguments that are passed to the object member during the invoke operation. For example, for the statement sampleObject.SampleMethod(100), 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 member 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 TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
        {
            //Try and find normal method
            MethodInfo method = FindMethod(binder.Name, args);
            Type       t;

            if (method == null)
            {
                //If we cant find one look for an event
                EventInfo evt = null;
                t = base.TargetType;
                do
                {
                    evt = t.GetEvent(binder.Name, this.AccessFlags);
                } while (evt == null && (t = t.BaseType) != null);

                if (evt != null)
                {
                    //Try and get the raise method
                    method = evt.GetRaiseMethod(true);
                    if (method == null)
                    {
                        //Look for the events backing field
                        var field = t.GetField(evt.Name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
                        if (field == null)
                        {
                            field = t.GetField("_" + evt.Name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
                            if (field == null)
                            {
                                field = t.GetField("m_" + evt.Name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
                            }
                        }
                        if (field != null)
                        {
                            var eventDelegate = (MulticastDelegate)field.GetValue(base.Target);
                            if (eventDelegate != null)
                            {
                                //Trigger each handler
                                foreach (var handler in eventDelegate.GetInvocationList())
                                {
                                    handler.Method.Invoke(handler.Target, args);
                                }
                                result = new DynamicReflector(evt, Target)
                                {
                                    WrapReturn = this.WrapReturn
                                };
                                return(true);
                            }
                        }

                        //If we still dont have one, look for an On[eventname] method to raise
                        method = FindMethod("On" + binder.Name, args);
                        if (method == null)
                        {
                            //Try without the sender argument
                            var a = args.Skip(1).ToArray();
                            method = FindMethod("On" + binder.Name, a);
                            if (method != null)
                            {
                                args = a;
                            }
                            else
                            {
                                result = new DynamicReflector(evt, Target)
                                {
                                    WrapReturn = this.WrapReturn
                                };
                                return(false);
                            }
                        }
                    }
                }
            }

            if (method != null)
            {
                result = method.Invoke(Target, args);
                if (WrapReturn)
                {
                    result = new DynamicReflector(result)
                    {
                        WrapReturn = this.WrapReturn
                    };
                }
                return(true);
            }

            //We arent invoking a method or event, so check for a nested type to construct
            Type nested = null;

            t = base.TargetType;
            do
            {
                nested = t.GetNestedType(binder.Name, this.AccessFlags);
            } while (nested == null && (t = t.BaseType) != null);

            if (nested != null)
            {
                var ctor = nested.GetConstructor(this.AccessFlags, null, args.Select(a => a == null ? null : a.GetType()).ToArray(), null);
                if (ctor != null)
                {
                    result = ctor.Invoke(args);
                    if (this.WrapReturn)
                    {
                        result = new DynamicReflector(result)
                        {
                            WrapReturn = this.WrapReturn
                        };
                    }
                    return(true);
                }
            }

            return(base.TryInvokeMember(binder, args, out result));
        }