Build() public method

public Build ( ) : Func,Task>
return Func,Task>
Ejemplo n.º 1
0
        public Func <IDictionary <string, object>, Task> Build()
        {
            var fixerSetupMethod = FindFixerSetupMethod();
            var fixer            = new Fixer();

            object instance = fixerSetupMethod.IsStatic || fixerSetupMethod.DeclaringType == null
                ? null
                : Activator.CreateInstance(fixerSetupMethod.DeclaringType);

            var parameters = new object[1];

            var parameterType = fixerSetupMethod.GetParameters().Single().ParameterType;

            if (parameterType.IsAssignableFrom(typeof(Fixer)))
            {
                parameters[0] = fixer;
            }
            else
            {
                var adapter = _adapters.FirstOrDefault(a => parameterType.IsAssignableFrom(a.AdaptedType));
                if (adapter != null)
                {
                    parameters[0] = adapter.Adapt(fixer);
                }
            }
            if (parameters[0] == null)
            {
                parameters[0] = new Action <Func <IDictionary <string, object>, Func <IDictionary <string, object>, Task>, Task> >(f => fixer.Use(f));
            }

            fixerSetupMethod.Invoke(instance, parameters);
            return(fixer.Build());
        }
Ejemplo n.º 2
0
        public Func<IDictionary<string, object>, Task> Build()
        {
            var fixerSetupMethod = FindFixerSetupMethod();
            var fixer = new Fixer();

            object instance = fixerSetupMethod.IsStatic || fixerSetupMethod.DeclaringType == null
                ? null
                : Activator.CreateInstance(fixerSetupMethod.DeclaringType);

            var parameters = new object[1];

            var parameterType = fixerSetupMethod.GetParameters().Single().ParameterType;
            if (parameterType.IsAssignableFrom(typeof (Fixer)))
            {
                parameters[0] = fixer;
            }
            else
            {
                var adapter = _adapters.FirstOrDefault(a => parameterType.IsAssignableFrom(a.AdaptedType));
                if (adapter != null)
                {
                    parameters[0] = adapter.Adapt(fixer);
                }
            }
            if (parameters[0] == null)
            {
                parameters[0] = new Action<Func<IDictionary<string, object>, Func<IDictionary<string, object>, Task>, Task>>(f => fixer.Use(f));
            }

            fixerSetupMethod.Invoke(instance, parameters);
            return fixer.Build();
        }
Ejemplo n.º 3
0
        public Func<IDictionary<string, object>, Task> Build()
        {
            var fixerSetupMethod = FindFixerSetupMethod();
            var fixer = new Fixer();

            object instance = fixerSetupMethod.IsStatic || fixerSetupMethod.DeclaringType == null
                ? null
                : CreateInstanceOfOwinAppSetupClass(fixerSetupMethod.DeclaringType);

            object[] parameters;

            var parameterInfos = fixerSetupMethod.GetParameters();
            if (parameterInfos.Length == 1)
            {
                parameters = new object[1];
                var parameterType = parameterInfos[0].ParameterType;
                if (parameterType.IsAssignableFrom(typeof (Fixer)))
                {
                    parameters[0] = fixer;
                }
                else
                {
                    var adapter = _adapters.FirstOrDefault(a => parameterType.IsAssignableFrom(a.AdaptedType));
                    if (adapter != null)
                    {
                        parameters[0] = adapter.Adapt(fixer);
                    }
                }
                if (parameters[0] == null)
                {
                    parameters[0] = new Action<Func<AppFunc, AppFunc>>(f => fixer.Use(f));
                }
            }
            else
            {
                var useAction = new Action<Func<AppFunc, AppFunc>>(f => fixer.Use(f));
                var mapAction = new Action<string, Func<AppFunc, AppFunc>>((p,f) => fixer.Map(p,f));
                parameters = new object[]{useAction, mapAction};
            }

            fixerSetupMethod.Invoke(instance, parameters);
            return fixer.Build();
        }