Example #1
0
        /// <summary>Raises an InvalidMiddlewareException if this method doesn't look valid, so we won't be able to Invoke it properly.</summary>
        public override void ValidateMethod(MethodInfo method)
        {
            var errors = new List <string>();

            if (!method.IsStatic)
            {
                errors.Add("Must be static");
            }

            if (!typeof(Response).IsAssignableFrom(method.ReturnType))
            {
                errors.Add("Must return a Response");
            }

            var parameters = method.GetParameters();

            if (parameters.Length != 2)
            {
                errors.Add("Must take 2 parameters (Request, Application)");
            }
            else
            {
                if (!parameters.First().ParameterType.IsAssignableFrom(typeof(Request)))
                {
                    errors.Add("Parameter 1 must be a Request");
                }
                if (!parameters.Last().ParameterType.IsAssignableFrom(typeof(Application)))
                {
                    errors.Add("Parameter 2 must be an Application");
                }
            }

            if (errors.Count > 0)
            {
                errors.Insert(0, Crack.FullMethodName(method) + " cannot be used as a Middleware");
                throw new InvalidMiddlewareException(string.Join(". ", errors.ToArray()) + ".");
            }
        }
Example #2
0
        /// <summary>Returns all of the Command found in the given Assembly (my looking for public static methods decorated with [Command]</summary>
        public static CommandList AllFromAssembly(Assembly assembly)
        {
            var all = Crack.GetMethodInfos <CommandAttribute>(assembly).Select(method => new Command(method)).ToList();

            return(new CommandList(all));
        }
Example #3
0
        /// <summary>Returns all of the Middleware found in the given Assembly (my looking for public static methods decorated with [Middleware]</summary>
        public static new MiddlewareList AllFromAssembly(Assembly assembly)
        {
            var middlewares = Crack.GetMethodInfos <MiddlewareAttribute>(assembly).Select(method => new Middleware(method)).ToList();

            return(new MiddlewareList(middlewares));
        }
Example #4
0
        /// <summary>Returns all of the Application found in the given Assembly (my looking for public static methods decorated with [Application]</summary>
        public static ApplicationList AllFromAssembly(Assembly assembly)
        {
            var all = Crack.GetMethodInfos <ApplicationAttribute>(assembly).Select(method => new Application(method)).ToList();

            return(new ApplicationList(all));
        }