Example #1
0
        private ICallReturn InterceptPropertySet(ICallInvocation invocation, GetNextCallHandlerDelegate getNext)
        {
            var propertyName = invocation.MethodBase.Name.Substring(4);

            var returnValue = getNext()(invocation, getNext);

            var subscribers = propertyChanged;

            if (subscribers != null)
            {
                subscribers(invocation.Target, new PropertyChangedEventArgs(propertyName));
            }

            return(returnValue);
        }
Example #2
0
        public ICallReturn Invoke(ICallInvocation invocation, GetNextCallHandlerDelegate getNext)
        {
            if (invocation.MethodBase == addEventMethodInfo)
            {
                return(AddEventSubscription(invocation));
            }

            if (invocation.MethodBase == removeEventMethodInfo)
            {
                return(RemoveEventSubscription(invocation));
            }

            if (IsPropertySetter(invocation))
            {
                return(InterceptPropertySet(invocation, getNext));
            }

            return(getNext()(invocation, getNext));
        }
Example #3
0
            public ICallReturn Invoke(ICallInvocation invocation, GetNextCallHandlerDelegate getNext)
            {
                if (cached == null)
                {
                    cached = new Dictionary <ElementCollection, CachingResult>();
                }

                var args = invocation.Arguments;
                var key  = new ElementCollection(args);

                CachingResult cachingResult;
                ICallReturn   result = null;

                if (cached.TryGetValue(key, out cachingResult))
                {
                    result = cachingResult.Result;
                    object value;
                    value = cachingResult.Lifetime.GetValue();
                    if (value != null)
                    //if (cachingResult.Lifetime.GetValue(out value))
                    {
                        result.ReturnValue = value;
                    }
                    else
                    {
                        cachingResult = null;
                        result        = null;
                    }
                }

                if (cachingResult == null)
                {
                    result = getNext()(invocation, getNext);
                    ILifetime lifetime = GetLifetime((MethodInfo)invocation.MethodBase, invocation.Target, result.ReturnValue, cachingData.lifetimeType, cachingData.lifetimeMethodName);
                    cachingResult = new CachingResult(result, lifetime);
                    cached[key]   = cachingResult;
                }

                return(result);
            }
Example #4
0
        public ICallReturn Invoke(ICallInvocation invocation, GetNextCallHandlerDelegate getNext)
        {
            object     result;
            MethodBase method = invocation.MethodBase;

            object[] args = invocation.Arguments.ToValueArray();
            try
            {
                result = method.Invoke(invocation.Target, args);
            }
            catch (TargetInvocationException ex)
            {
                return(invocation.ReturnException(ex.InnerException));
            }


            return(invocation.Return(result));
        }