Exemple #1
0
        static void Main(string[] args)
        {
            Action <int> a = action;

            a(9);

            #region 监听测试
            //string[] pric = new string[] { "http://localhost:3721/" };
            //SimpleListenerExample(pric);
            #endregion

            #region 抽象类测试
            //HttpContext hc = new DefaultHttpContext();
            //HttpRequest hr = new DefaultHttpRequest();
            //string urk = hr.uRL;
            //string url= hc.Request.uRL;

            #endregion

            #region 特性测试
            //声明一个接口实例,但不是对接口进行实例化
            //IFeatureCollection _feature = new FeatureCollection();
            //_feature.Set(new Persion());
            //var d = _feature.Get<Persion>();
            //string s = d.wan();
            Isx isx = new Isx();
            IFeatureCollection _feature = new FeatureCollection();
            _feature.Set <ITestin>(isx);
            var    d = _feature.Get <ITestin>();
            string s = d.PathBase;
            #endregion

            #region 管道测试 和 下面的Startup测试 是结合的
            //Middleware midd = new Middleware();
            #region test
            //同步
            //Func<RequsetDelegate, RequsetDelegate> context3 = next =>
            //{
            //    return  context =>
            //    {
            //        //app("刘哲");调用委托 执行绑定在委托上的方法
            //         Task.Run(() => Console.WriteLine(context + "1"));
            //         return next(context);
            //    };
            //};
            //异步
            //Func<RequsetDelegate, RequsetDelegate> context4 = next =>
            //{
            //    return async context =>
            //    {
            //        //app("刘哲");调用委托 执行绑定在委托上的方法
            //        await Task.Run(() => Console.WriteLine(context + "1"));
            //        await next(context);
            //    };
            //};
            //Func<RequsetDelegate, RequsetDelegate> context4 = next =>
            //{
            //    return async context =>
            //    {
            //        await Task.Run(() => Console.WriteLine(context + "2"));
            //        //await next(context);
            //    };
            //};
            //Func<RequsetDelegate, RequsetDelegate> context1 = mi1;
            //Func<RequsetDelegate, RequsetDelegate> context2 = mi2;
            //midd.Use(context1);
            //midd.Use(context2);
            //midd.Use(next =>//next也就是T2
            //{
            //    return async context =>
            //    {
            //        await Task.Run(() => Console.WriteLine(context + "3"));
            //        await next(context);//实现T2
            //    };
            //});
            //midd.Use(next =>//next是上一个委托,这里是最后一个是默认的空处理
            //{
            //    return async context =>
            //    {
            //        await Task.Run(() => Console.WriteLine(context + "4"));
            //        await next(context);
            //    };
            //});
            //RequsetDelegate app = midd.Build();//返回的是T1
            //app("刘哲");//调用t1 启动管道
            #endregion

            #endregion

            #region Startup测试
            Middleware middware = new Middleware();
            //相当于app项目中IWebHostBuilder Configure中的new DelegateStartup(configure)
            DelegateStartup ds = new DelegateStartup(Middle);
            ds.Configure(middware);                 //也就是调用注册中间件(Middle 方法里面的use)方法use 相当于a(9);
            RequsetDelegate app = middware.Build(); //返回的是T1 相当于Func<string, string> f = HelloEnglish
            app("刘哲");                              //调用t1 启动管道 启动中间件方法
            #endregion

            #region 调用委托
            //var list = new MyList();
            //list._List.Add(true);
            //list._List.Add(false);
            //list._List.Add(true);
            //int count = list._List.Count;
            ////实现委托
            //list.FuncAllLen += Temp;//实现将方法赋值给委托属性
            //Console.WriteLine(list.AllLen().ToString());//调用委托
            #endregion


            Console.ReadKey();
        }
 //调用构造函数注册的方法 a(9) 相当于调用Middle 方法
 public void Configure(Middleware app)
 {
     //相当于调用Middle 方法
     //string s= f("Srping ji")//调用委托,实际是调用委托的实现方法
     _configure(app);
 }