• C# => 写法


            public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
                WebHost.CreateDefaultBuilder(args)
                    .UseStartup<Startup>();
    
    
            public static IWebHostBuilder CreateWebHostBuilder(string[] args)
            {
                return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
            }
     Action<object> action = 
               //函数参数
                (object obj) 
                =>
                //函数体
                {
                    Console.WriteLine("123456");
                };
    
           public void action <T>(object obj)
            {
                Console.WriteLine("123456");
            }
            public void test()
            {
                Action<object> action = new Action<object>(action<object>);
                action(new object()); //执行
            }
      //我的自定义委托
            public delegate Task Request_Delegate(HttpContext context);
            //我的自定义函数
            public Task My_Function(HttpContext context)
            {
                return context.Response.WriteAsync("1213465656");
            }
      /*
                 写法1
                 */
                app.Run(
                    async (context)
                    =>
                    {
                        await context.Response.WriteAsync("Hello World!_001");
                    }
                );
                /*
                 写法 2
                 */
                test(app);
    
                app.Run(
                     (context)     // 类似于匿名函数
                     =>
                     {
                         return context.Response.WriteAsync("Hello World!");
                     }
    #region --定义带参数的委托
            //定义一个委托
            public delegate TResult My_Func001<in T1, in T2, out TResult>(T1 arg1, T2 arg2);
            public delegate string My_Func0011<in T1, in T2, out TResult>(T1 arg1, T2 arg2);
            public string  my_func001<T1,T2>(int a,int b)
            {
                MessageBox.Show("0");
                return "";
            }
            /*
             My_Func001<int, int,string> my_Func001 = my_func001<int, int>;
             my_Func001(1,2); 
    
            My_Func0011<int, int, string> my_Func001 = my_func001<int, int>;
            my_Func001(1, 2);
    
              */
    
            public delegate void My_Func002<in T1, in T2>(T1 arg1, T2 arg2);
            public void my_func002<T1,T2>(T1 a,T2 b){}
            /*
            My_Func002<int,int> my_Func002 = my_func002<int, int>;
            my_Func002(10,11);
             */
            #endregion
    
            #region --定义无参数的委托
            public delegate void My_Func003<in T1, in T2>(); //无参数
            public void my_func003()
            {
                MessageBox.Show("003");
            }
            public void my_func003<T>()
            {
                var t = typeof(T);
                MessageBox.Show("003<T>" + t.Name);
            }
            public void my_func003<T1, T2>()
            {
                var t = typeof(T1);
                MessageBox.Show("003<T1,T2>" + t.Name);
            }
            /*
             调用
               //声明委托
                My_Func003<int, int> my_Func003 = my_func003;
                My_Func003<int, int> my_Func003_1 = my_func003<String>;
                My_Func003<int, int> my_Func003_12 = my_func003<String, String>;
                //执行委托
                my_Func003();
                my_Func003_1();
                my_Func003_12();
            */
    
            #endregion

     //研究中e......

    namespace WebApplication1.lib
    {
        //定义一个接口
        public interface My_IApplicationBuilder
        {
            My_IApplicationBuilder Use(Func<RequestDelegate, RequestDelegate> middleware);
        }
        public static class A
        {
            // public delegate TResult Func<in T, out TResult>(T arg);
    
            public static T test<T>(T a)
            {
                T temp = default(T);
    
                return temp;
            }
            public static My_IApplicationBuilder testc(this My_IApplicationBuilder app, string str)
            {
    
                Func<RequestDelegate, RequestDelegate> middleware = test<RequestDelegate>;
                //执行这个函数
                //return app.Use(middleware); //函数当参数传递过去
    
                //委托赋值方式 2
                Func<RequestDelegate, RequestDelegate> middleware1 = delegate (RequestDelegate next)
                {
    
                    //返回方法001
                    MethodInfo[] array = new MethodInfo[] { };
                    MethodInfo methodInfo = array[0];
                    return (RequestDelegate)new object();
       
                }; //匿名方法
    
                return app.Use(middleware1); //函数当参数传递过去
            }
    
        }
    }

     gg了

    .net core    如何获取 每次请求URL    比如  http://localhost:62830/h        http://localhost:62830/a.txt     http://localhost:62830/a.jpg   http://localhost:62830/a     http://localhost:62830/b

    服务器如何获取 每次的请求连接?????

             //app.Run(My_Function);  // 放在 app.UseMvc 之后,将捕获不到控制器页面       捕获所有请求

    ////我的自定义函数 //public async Task My_Function( HttpContext context) //{ // //RequestHandleHelper request = new RequestHandleHelper(context.Request); // //var t = ; //请求路径 // var path = context.Request.Path.Value; // var met = context.Request.Method; // //包含的文件扩展名 // if (path=="1") // { // //context.Response.Redirect(path); // //await context.Response.WriteAsync("Hello, World!"); // } // else if(path== "/123") // { // context.Response.Redirect("/Home/Error"); // } //}

     //其他委托

     //定义一个接口
        public interface My_IApplicationBuilder
        {
            My_IApplicationBuilder Use(Func<RequestDelegate, RequestDelegate> middleware);
        }
        public static class A
        {
            // public delegate TResult Func<in T, out TResult>(T arg);
    
            public static T test<T>(T a)
            {
                T temp = default(T);
    
                return temp;
            }
            public static My_IApplicationBuilder testc(this My_IApplicationBuilder app, string str)
            {
    
                Func<RequestDelegate, RequestDelegate> middleware = test<RequestDelegate>;
                //执行这个函数
                //return app.Use(middleware); //函数当参数传递过去
    
                //委托赋值方式 2
                Func<RequestDelegate, RequestDelegate> middleware1 = delegate (RequestDelegate next)
                {
    
                    //返回方法001
                    MethodInfo[] array = new MethodInfo[] { };
                    MethodInfo methodInfo = array[0];
                    return (RequestDelegate)new object();
       
                }; //匿名方法
    
                return app.Use(middleware1); //函数当参数传递过去
            }
    
        }
  • 相关阅读:
    JavaScript:Number 对象
    JavaScript:Math 对象
    杂项:引用资源列表
    小团队管理与大团队管理
    技术转管理
    【翻译+整理】.NET Core的介绍
    自己开发给自己用的个人知识管理工具【脑细胞】,源码提供
    关于【自证清白】
    这篇博客能让你戒烟——用程序员的思维来戒烟!
    如果我是博客园的产品经理【下】
  • 原文地址:https://www.cnblogs.com/enych/p/11737726.html
Copyright © 2020-2023  润新知