Пример #1
0
        public object Invoke(object obj, object[] arguments)
        {
            object result = _methodInfo.Invoke(obj, arguments);

            object[] attributes = _methodInfo.GetCustomAttributes(false);
            if (attributes != null && attributes.Length > 0)
            {
                InvocationManager invocationManager = new InvocationManager();
                invocationManager.Result = result;
                for (int i = 0; i < attributes.Length; i++)
                {
                    Attribute attribute = attributes[i] as Attribute;
                    if (attribute is IInvocationCallback)
                    {
                        IInvocationCallback invocationCallback = attribute as IInvocationCallback;
                        invocationCallback.OnInvoked(invocationManager, _methodInfo, obj, arguments, result);
                    }
                }
                for (int i = 0; i < attributes.Length; i++)
                {
                    Attribute attribute = attributes[i] as Attribute;
                    if (attribute is IInvocationResultHandler)
                    {
                        IInvocationResultHandler invocationResultHandler = attribute as IInvocationResultHandler;
                        invocationResultHandler.HandleResult(invocationManager, _methodInfo, obj, arguments, result);
                    }
                }
                return(invocationManager.Result);
            }
            return(result);
        }
Пример #2
0
        public async Task <object> Invoke(object obj, object[] arguments)
        {
            object result = null;

            if (_methodInfo.GetCustomAttribute(typeof(AsyncStateMachineAttribute)) == null)
            {
                result = _methodInfo.Invoke(obj, arguments);
            }
            else
            {
                Task  task = (Task)_methodInfo.Invoke(obj, arguments);
                await task;
                result = task.GetType().GetProperty("Result").GetValue(task);
            }

            object[] attributes = _methodInfo.GetCustomAttributes(false);
            if (attributes != null && attributes.Length > 0)
            {
                InvocationManager invocationManager = new InvocationManager();
                invocationManager.Result = result;
                for (int i = 0; i < attributes.Length; i++)
                {
                    Attribute attribute = attributes[i] as Attribute;
                    if (attribute is IInvocationCallback)
                    {
                        IInvocationCallback invocationCallback = attribute as IInvocationCallback;
                        invocationCallback.OnInvoked(invocationManager, _methodInfo, obj, arguments, result);
                    }
                }
                for (int i = 0; i < attributes.Length; i++)
                {
                    Attribute attribute = attributes[i] as Attribute;
                    if (attribute is IInvocationResultHandler)
                    {
                        IInvocationResultHandler invocationResultHandler = attribute as IInvocationResultHandler;
                        invocationResultHandler.HandleResult(invocationManager, _methodInfo, obj, arguments, result);
                    }
                }
                return(invocationManager.Result);
            }
            return(result);
        }