Example #1
0
        private static async Task <Tuple <object[], IDelayedException> > PrepareParametersAsync(IReadOnlyList <string> parameterNames,
                                                                                                IReadOnlyDictionary <string, IValueProvider> parameters)
        {
            object[]         reflectionParameters = new object[parameterNames.Count];
            List <Exception> bindingExceptions    = new List <Exception>();

            for (int index = 0; index < parameterNames.Count; index++)
            {
                string         name     = parameterNames[index];
                IValueProvider provider = parameters[name];

                BindingExceptionValueProvider exceptionProvider = provider as BindingExceptionValueProvider;

                if (exceptionProvider != null)
                {
                    bindingExceptions.Add(exceptionProvider.Exception);
                }

                reflectionParameters[index] = await parameters[name].GetValueAsync();
            }

            IDelayedException delayedBindingException = null;

            if (bindingExceptions.Count == 1)
            {
                delayedBindingException = new DelayedException(bindingExceptions[0]);
            }
            else if (bindingExceptions.Count > 1)
            {
                delayedBindingException = new DelayedException(new AggregateException(bindingExceptions));
            }

            return(new Tuple <object[], IDelayedException>(reflectionParameters, delayedBindingException));
        }
        private static object[] PrepareParameters(IReadOnlyList <string> parameterNames,
                                                  IReadOnlyDictionary <string, IValueProvider> parameters, out IDelayedException delayedBindingException)
        {
            object[]         reflectionParameters = new object[parameterNames.Count];
            List <Exception> bindingExceptions    = new List <Exception>();

            for (int index = 0; index < parameterNames.Count; index++)
            {
                string         name     = parameterNames[index];
                IValueProvider provider = parameters[name];

                BindingExceptionValueProvider exceptionProvider = provider as BindingExceptionValueProvider;

                if (exceptionProvider != null)
                {
                    bindingExceptions.Add(exceptionProvider.Exception);
                }

                reflectionParameters[index] = parameters[name].GetValue();
            }

            if (bindingExceptions.Count == 0)
            {
                delayedBindingException = null;
            }
            else if (bindingExceptions.Count == 1)
            {
                delayedBindingException = new DelayedException(bindingExceptions[0]);
            }
            else
            {
                delayedBindingException = new DelayedException(new AggregateException(bindingExceptions));
            }

            return(reflectionParameters);
        }