示例#1
0
        private static object Call(
            TService service,
            TPolicyProvider policyProvider,
            MethodInfo methodInfo,
            object[] args,
            IContextProvider contextProvider)
        {
            var cb = new Func <object>(() => SyncMethodCache <TService> .Call(service, methodInfo, args));

            return(Execute(cb, service, methodInfo, args, policyProvider, contextProvider));
        }
示例#2
0
        public static object Invoke(
            TService service,
            TPolicyProvider policyProvider,
            IContextProvider contextProvider,
            MethodInfo methodInfo,
            object[] args)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (policyProvider == null)
            {
                throw new ArgumentNullException(nameof(policyProvider));
            }
            if (contextProvider == null)
            {
                throw new ArgumentNullException(nameof(contextProvider));
            }
            if (methodInfo == null)
            {
                throw new ArgumentNullException(nameof(methodInfo));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            try
            {
                if (GettersCache <TService> .Handles(methodInfo))
                {
                    return(Get(service, policyProvider, methodInfo, contextProvider));
                }

                if (IndexedGettersCache <TService> .Handles(methodInfo))
                {
                    return(Get(service, policyProvider, methodInfo, args, contextProvider));
                }

                if (SettersCache <TService> .Handles(methodInfo))
                {
                    Set(service, policyProvider, methodInfo, args.Single(), contextProvider);
                    return(null);
                }

                if (IndexedSettersCache <TService> .Handles(methodInfo))
                {
                    Set(service, policyProvider, methodInfo, args.Take(args.Length - 1).ToArray(), args.Last(), contextProvider);
                    return(null);
                }

                if (SyncMethodCache <TService> .Handles(methodInfo))
                {
                    return(Call(service, policyProvider, methodInfo, args, contextProvider));
                }

                if (AsyncMethodCache <TService> .Handles(methodInfo))
                {
                    return(CallAsync(service, policyProvider, methodInfo, args, contextProvider));
                }

                throw new NotSupportedException($"The method {methodInfo} is not supported.");
            }
            catch (TargetInvocationException ex)
            {
                throw ex.GetBaseException() ?? ex.InnerException ?? ex;
            }
        }