Esempio n. 1
0
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            if (CallTarget == null)
            {
                return(false);
            }

            if (InvocationBinding.InvokeIsEvent(CallTarget, binder.Name) && value is InterceptorAddRemove)
            {
                var theValue = value as InterceptorAddRemove;

                if (theValue.IsAdding)
                {
                    InvocationBinding.InvokeAddAssign(CallTarget, binder.Name, theValue.Delegate);
                }
                else
                {
                    InvocationBinding.InvokeSubtractAssign(CallTarget, binder.Name, theValue.Delegate);
                }

                return(true);
            }

            InvocationBinding.InvokeSet(CallTarget, binder.Name, value);

            return(true);
        }
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            object tOldValue;

            var          sk     = SignatureKey.Create(binder);
            SignatureKey nested = null;

            if (_nestedTargets.TryGetValue(sk, out nested))
            {
                var member = _dynamicMembers[nested];
                InvocationBinding.InvokeSet(member, binder.Name, value);
            }
            else if (!_dynamicMembers.TryGetValue(sk, out tOldValue) || value != tOldValue)
            {
                _dynamicMembers[sk] = value;
            }

            return(true);
        }
Esempio n. 3
0
        public virtual object Invoke(object target, params object[] args)
        {
            switch (Kind)
            {
            case InvocationKind.Constructor:
                return(InvocationBinding.CreateInstance((Type)target, args));

            case InvocationKind.Convert:
                bool tExplict = false;
                if (Arguments.Length == 2)
                {
                    tExplict = (bool)args[1];
                }
                return(InvocationBinding.Conversion(target, (Type)args[0], tExplict));

            case InvocationKind.Get:
                return(InvocationBinding.InvokeGet(target, Name.Name));

            case InvocationKind.Set:
                InvocationBinding.InvokeSet(target, Name.Name, args.FirstOrDefault());
                return(null);

            case InvocationKind.GetIndex:
                return(InvocationBinding.InvokeGetIndex(target, args));

            case InvocationKind.SetIndex:
                InvocationBinding.InvokeSetIndex(target, args);
                return(null);

            case InvocationKind.InvokeMember:
                return(InvocationBinding.InvokeMember(target, Name, args));

            case InvocationKind.InvokeMemberAction:
                InvocationBinding.InvokeMemberAction(target, Name, args);
                return(null);

            case InvocationKind.InvokeMemberUnknown:
            {
                try
                {
                    return(InvocationBinding.InvokeMember(target, Name, args));
                }
                catch (RuntimeBinderException)
                {
                    InvocationBinding.InvokeMemberAction(target, Name, args);
                    return(null);
                }
            }

            case InvocationKind.Invoke:
                return(InvocationBinding.Invoke(target, args));

            case InvocationKind.InvokeAction:
                InvocationBinding.InvokeAction(target, args);
                return(null);

            case InvocationKind.InvokeUnknown:
            {
                try
                {
                    return(InvocationBinding.Invoke(target, args));
                }
                catch (RuntimeBinderException)
                {
                    InvocationBinding.InvokeAction(target, args);
                    return(null);
                }
            }

            case InvocationKind.AddAssign:
                InvocationBinding.InvokeAddAssign(target, Name.Name, args.FirstOrDefault());
                return(null);

            case InvocationKind.SubtractAssign:
                InvocationBinding.InvokeSubtractAssign(target, Name.Name, args.FirstOrDefault());
                return(null);

            case InvocationKind.IsEvent:
                return(InvocationBinding.InvokeIsEvent(target, Name.Name));

            default:
                throw new InvalidOperationException("Unknown Invocation Kind: " + Kind);
            }
        }