Use() public method

public Use ( Func,Task>,Func,Task>> component ) : Fixer
component Func,Task>,Func,Task>>
return Fixer
Exemplo 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();
        }
Exemplo 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());
        }
Exemplo n.º 3
0
 public static void Setup(Fixer fixer)
 {
     fixer.Use(Application.Run);
 }
Exemplo n.º 4
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();
        }