Пример #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);
        }
Пример #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);
     }));
 }
Пример #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);
        }
Пример #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);
        }
Пример #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));
     }