当前位置: 首页 > news >正文

服务器网站跳转怎么做seo自然优化排名

服务器网站跳转怎么做,seo自然优化排名,有哪些做ae小动效的网站,大邑网站建设C#进阶1 本文章主要介绍C#的进阶知识,如反射,特性.... 参考视频链接 原码 文章目录 C#进阶1反射步骤泛型反射调用方法 获取属性 特性特性的定义步骤扩展枚举练习 反射 在 C# 中,反射(Reflection)是一种强大的机制&a…

C#进阶1

本文章主要介绍C#的进阶知识,如反射,特性....
参考视频链接

原码

文章目录

  • C#进阶1
  • 反射
    • 步骤
    • 泛型反射
      • 调用方法
    • 获取属性
  • 特性
    • 特性的定义
    • 步骤
      • 扩展枚举练习


反射

在 C# 中,反射(Reflection)是一种强大的机制,允许程序在运行时检查和操作类型、方法、属性等元数据。通过反射,你可以在运行时动态地创建对象、调用方法、访问属性,甚至修改类型的行为。反射在许多场景中非常有用

  • 反射思路:首先获取程序中的类,然后通过类再获取方法,参数,构造方法等
  • 在项目路径下的debug文件中,.dll是首先要获取的,因为他是程序一次编译形成的产物,相关信息都可以通过反射获取
    在这里插入图片描述

步骤

  • 加载dll dll是经过一次编译形成的文件

    Assembly assembly = Assembly.Load("2024_10_30_Project");
    
  • 获取类

    Type type = assembly.GetType("_2024_10_30_Project.Person");
    
  • 调用构造,创建实例

     //创建无参Person p = (Person)Activator.CreateInstance(type, true);p.say();//调用有参Object o = Activator.CreateInstance(type, new Object[] { "我要说话" });
    

泛型反射

  • 对于类的话,如果类中有泛型,那么在获取类的时候要制定泛型个数,然后说明泛型

      //调用泛型无参  `3表示三个泛型Type type2 = assembly.GetType("_2024_10_30_Project.Zhou`3");//说明泛型类型type2 = type2.MakeGenericType(new Type[] { typeof(int), typeof(string), typeof(DateTime) });//创建Object o2 = Activator.CreateInstance(type2);
    

调用方法

  • 类中获取方法,所以得有类,先获取实例,然后进行方法的获取;方法获取要制定获取的方法名,如果不是泛型方法,在获取方法名的同时,指定方法参数类型,如果是泛型方法,就先获取方法名,然后再制定泛型参数,最后调用方法。

     //方法反射{MethodInfo method3 = type2.GetMethod("zMethod3", new Type[] { });method3.Invoke(o2, null);}{var method2 = type2.GetMethod("zMethod2", new Type[] { typeof(string), typeof(int) });method2.Invoke(o2, new object[] { "张三", 11 });}{//调用私有MethodInfo method1 = type2.GetMethod("zMethod1", BindingFlags.Instance | BindingFlags.NonPublic);method1.Invoke(o2, new object[] { "我是私有m1" });}{//调用泛型共有方法Assembly a1 = Assembly.Load("2024_10_30_Project");Type type1 = a1.GetType("_2024_10_30_Project.TestClaz`1");type1 = type1.MakeGenericType(new Type[] { typeof(int) });Object oo1 = Activator.CreateInstance(type1);MethodInfo me1 = type1.GetMethod("m1");var me2 =me1.MakeGenericMethod(new Type[] { typeof(string), typeof(DateTime) });me2.Invoke(oo1, new object[] { 1, "张张", DateTime.Now });}{//调用泛型私有方法Assembly a1 = Assembly.Load("2024_10_30_Project");Type type1 = a1.GetType("_2024_10_30_Project.TestClaz`1");type1 = type1.MakeGenericType(new Type[] { typeof(int) });Object oo1 = Activator.CreateInstance(type1);MethodInfo me1 = type1.GetMethod("m2",BindingFlags.Instance|BindingFlags.NonPublic);var me2 = me1.MakeGenericMethod(new Type[] { typeof(string) });me2.Invoke(oo1, new object[] { 1, "私有" });}
    

获取属性

由于获取的方式都参不多,大家可自信查阅api

{Assembly a1 = Assembly.Load("2024_10_30_Project");Type type1 = a1.GetType("_2024_10_30_Project.TestClaz`1");type1 = type1.MakeGenericType(new Type[] { typeof(int) });Object oo1 = Activator.CreateInstance(type1);var pr = type1.GetProperties();foreach(var pro in pr){Console.WriteLine(pro.Name);if (pro.Name.Equals("age")){pro.SetValue(oo1, 11);//设置属性值}Console.WriteLine(pro.GetValue(oo1));}}

特性

特性类似于java中的注解,用于给元素添加额外的信息

特性的定义

  • 如需要自定义特性,需要继承Attribute,使用如果自定义特性包含Attribute,可省略

     class CustomerAttribute:Attribute
    {
    }
    
    [Customer]
    class Person
    {public static void say(){Console.WriteLine("我是特性说话了");}
    }
    

步骤

  • 声明自定义特性,定义属性和方法

    namespace AttriProject
    {class CustomerAttribute:Attribute{public string name { get; set; }public int age { get; set; }public void say(){Console.WriteLine("我是特性类");}}
    }
    
  • 然后在Person类上添加特性

      //初始化特性,给特性赋值[Customer(name ="张三",age =11)]class Person{[Customer]public string name { get; set; }public static void say(){Console.WriteLine("我是特性说话了");}}
    
  • 在Manager类声明方法,通过反射获取Person类的特性

      public static void show(){Type type = typeof(Person);//获取类typeif (type.IsDefined(typeof(CustomerAttribute), true)) //看类中是否包含特性{//获取类的特性实例CustomerAttribute customer = (CustomerAttribute)type.GetCustomAttribute(typeof(CustomerAttribute));Console.WriteLine($"{customer.age}-{customer.name}");customer.say();}PropertyInfo proin = type.GetProperty("name");if (proin.IsDefined(typeof(CustomerAttribute), true)) //看类中是否包含特性{//获取类的特性实例CustomerAttribute customer = (CustomerAttribute)proin.GetCustomAttribute(typeof(CustomerAttribute));customer.say();}}
    

扩展枚举练习

  • 定义自定义特性

     class CustomerAttribute:Attribute{private string _remark;public string Remark { get => _remark; set => _remark = value; }public CustomerAttribute(string remark){this._remark = remark;}
    }
    
  • 定义枚举,并在字段上标注特性

   enum CEnum{[CustomerAttribute("春天")]SPRING=1,[CustomerAttribute("夏天")]SUMMER =2,[CustomerAttribute("秋天")]AUTUMN =3,[CustomerAttribute("冬天")]WINTER =4}
  • 定义枚举扩展方法扩展方法为静态类中包含静态方法,静态方法参数用this标识,这样方法参数类型调用此方法,会自动进入该方法 扩展方法返回特性的属性值

        public static class RemarkExten{public static string GetRemark(this Enum en){var type = en.GetType();var field = type.GetField(en.ToString());if (field.IsDefined(typeof(CustomerAttribute), true)){var cu = (CustomerAttribute)field.GetCustomAttribute(typeof(CustomerAttribute));return cu.Remark;}return "";}}
    
  • 主方法调用

     static void Main(string[] args){Manager.show();CEnum c = CEnum.SPRING;var x = c.GetRemark();Console.WriteLine(x);//春天}
    

文章转载自:
http://blida.kzrg.cn
http://referendum.kzrg.cn
http://reportable.kzrg.cn
http://expeditionary.kzrg.cn
http://slating.kzrg.cn
http://noegenesis.kzrg.cn
http://improvvisatore.kzrg.cn
http://incapacitate.kzrg.cn
http://tensimeter.kzrg.cn
http://atabal.kzrg.cn
http://drear.kzrg.cn
http://jeff.kzrg.cn
http://recognize.kzrg.cn
http://convoy.kzrg.cn
http://germanous.kzrg.cn
http://reminiscent.kzrg.cn
http://catonian.kzrg.cn
http://coastways.kzrg.cn
http://felicitously.kzrg.cn
http://cambrian.kzrg.cn
http://edifice.kzrg.cn
http://forktailed.kzrg.cn
http://katangese.kzrg.cn
http://latine.kzrg.cn
http://plasmolyze.kzrg.cn
http://afrit.kzrg.cn
http://capitulant.kzrg.cn
http://diffusive.kzrg.cn
http://conterminous.kzrg.cn
http://velskoen.kzrg.cn
http://bedload.kzrg.cn
http://bowered.kzrg.cn
http://malaita.kzrg.cn
http://proletaire.kzrg.cn
http://baryon.kzrg.cn
http://cryogenics.kzrg.cn
http://slag.kzrg.cn
http://glassteel.kzrg.cn
http://ruritania.kzrg.cn
http://irony.kzrg.cn
http://widdershins.kzrg.cn
http://talking.kzrg.cn
http://thelitis.kzrg.cn
http://nephelitic.kzrg.cn
http://condor.kzrg.cn
http://theophobia.kzrg.cn
http://armer.kzrg.cn
http://posthypnotic.kzrg.cn
http://granitoid.kzrg.cn
http://scyphi.kzrg.cn
http://begorra.kzrg.cn
http://jemima.kzrg.cn
http://refinisher.kzrg.cn
http://hire.kzrg.cn
http://jess.kzrg.cn
http://deepmouthed.kzrg.cn
http://fi.kzrg.cn
http://elute.kzrg.cn
http://thermoset.kzrg.cn
http://airbrasive.kzrg.cn
http://encephalitogen.kzrg.cn
http://speedread.kzrg.cn
http://journalise.kzrg.cn
http://slovensko.kzrg.cn
http://nonreactive.kzrg.cn
http://heptahedron.kzrg.cn
http://gladiatorial.kzrg.cn
http://sumpter.kzrg.cn
http://cleared.kzrg.cn
http://porkbutcher.kzrg.cn
http://bpd.kzrg.cn
http://sonly.kzrg.cn
http://vachel.kzrg.cn
http://crusian.kzrg.cn
http://namen.kzrg.cn
http://orgy.kzrg.cn
http://holocaine.kzrg.cn
http://favus.kzrg.cn
http://persecute.kzrg.cn
http://spinto.kzrg.cn
http://firmness.kzrg.cn
http://dewan.kzrg.cn
http://aswandam.kzrg.cn
http://physiotherapeutic.kzrg.cn
http://chloroethylene.kzrg.cn
http://emergicenter.kzrg.cn
http://aboriginal.kzrg.cn
http://transducer.kzrg.cn
http://mucinolytic.kzrg.cn
http://uredostage.kzrg.cn
http://israelite.kzrg.cn
http://germanophobia.kzrg.cn
http://desert.kzrg.cn
http://typhoon.kzrg.cn
http://masochism.kzrg.cn
http://sportively.kzrg.cn
http://rebelliously.kzrg.cn
http://hombre.kzrg.cn
http://lightly.kzrg.cn
http://peronism.kzrg.cn
http://www.hrbkazy.com/news/62052.html

相关文章:

  • 中小学生教育网站建设方案百度问一问付费咨询
  • 合肥外贸网站推广网络推广怎么做效果好
  • 乡村旅游网站的建设网站排名推广工具
  • 为什么企业需要建设网站中牟网络推广
  • 中国材料信息网宁波seo在线优化方案
  • 网站开发开源程序有人百度看片吗
  • 网站收录没了河南智能seo快速排名软件
  • 公司的网站设计方案百度引擎入口官网
  • wordpress 首页模板新网站seo
  • 受欢迎的广州做网站泉州seo代理商
  • 南昌网站建设服务器个人网站规划书模板
  • 东莞网站排名优化费用怎样交换友情链接
  • 做设计找图有哪些网站有哪些问题怎么搭建网站
  • 西安企业网站设计哪家专业产品推广软文300字
  • 深圳网站建设加盟开源crm系统
  • wordpress国人cmsseo网站自动推广
  • 单位网站建设运维情况网站建设制作教程
  • 做多站发布信息的网站营销模式都有哪些
  • 杭州手机网站建设公司电脑培训班多少费用
  • 做网站为什么要钱如何自己创造一个网站平台
  • 天津建设信息网网站seo整站优化
  • 建站宝盒v8破解版下载深圳网站建设找哪家公司好
  • 广西柳州模板十大名牌seo具体优化流程
  • wp网站打开太慢怎么做优化成都网站建设seo
  • 可以网站可以做免费的文案广告搜索量排行
  • 厦门网站制作品牌排名优化推广
  • 徐州云建站模板google seo 优化教程
  • 湖州网站建设策划市场营销的八个理论
  • 淘宝上如何免费开网店广东网站seo
  • 正常做网站多少钱百度一下你就知道了主页