Ejemplo n.º 1
0
        public static HttpRouter MapAttribute(this HttpRouter @this, HandlerCompiler compiler, Func <MethodInfo, IHttpHandler[], IHttpHandler[], IHttpHandler, IHttpHandler> handlerDelegate)
        {
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }
            if (compiler == null)
            {
                throw new ArgumentNullException(nameof(compiler));
            }

            var currentAssembly = typeof(HttpRouterExtensions).Assembly.GetName();
            var assemblies      = AssemblyLoadContext.Default.Assemblies;

            foreach (var assembly in assemblies)
            {
                var referencedAssemblies = assembly.GetReferencedAssemblies();
                foreach (var referencedAssembly in referencedAssemblies)
                {
                    if (AssemblyName.ReferenceMatchesDefinition(currentAssembly, referencedAssembly))
                    {
                        MapAttribute(@this, assembly.GetExportedTypes(), compiler, handlerDelegate);
                        break;
                    }
                }
            }
            return(@this);
        }
Ejemplo n.º 2
0
 public static HttpRouter MapAttribute(this HttpRouter @this, Type[] types, HandlerCompiler compiler)
 {
     return(MapAttribute(@this, types, compiler,
                         (method, typeHandlers, methodHandlers, handler) => {
         var handlers = new List <IHttpHandler>();
         handlers.AddRange(typeHandlers);
         handlers.AddRange(methodHandlers);
         handlers.Add(handler);
         return HttpHandler.CreatePipeline(handlers);
     }));
 }
Ejemplo n.º 3
0
        public static HttpRouter MapSlash(this HttpRouter @this)
        {
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }

            @this.GetTree.MapSlash();
            @this.PostTree.MapSlash();
            @this.PutTree.MapSlash();
            @this.DeleteTree.MapSlash();
            @this.HeadTree.MapSlash();
            return(@this);
        }
Ejemplo n.º 4
0
        public static HttpRouter MapGet(this HttpRouter @this, string template, Action <HttpRequest, HttpResponse> handler)
        {
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            @this.GetTree.Map(template, HttpHandler.Create(handler));
            return(@this);
        }
Ejemplo n.º 5
0
 public static HttpRouter MapAttribute(this HttpRouter @this, Type[] types, HandlerCompiler compiler, Func <MethodInfo, IHttpHandler[], IHttpHandler[], IHttpHandler, IHttpHandler> handlerDelegate)
 {
     if (@this == null)
     {
         throw new ArgumentNullException(nameof(@this));
     }
     if (types == null)
     {
         throw new ArgumentNullException(nameof(types));
     }
     if (compiler == null)
     {
         throw new ArgumentNullException(nameof(compiler));
     }
     if (handlerDelegate == null)
     {
         throw new ArgumentNullException(nameof(handlerDelegate));
     }