2.反射

反射调用类 ioc

反射调用方法 MVC URL地址一般是类名称+方法名

反射操作属性和方法 反射操作属性字段 ORM

模型转换(有点意思)

  public static void CoventClass<D>(People p,ref D d)
            where D : new()
        {
            Type t1 = d.GetType();
           // D d1= new D();
            foreach (PropertyInfo item in t1.GetProperties())
            {
                if (item.Name == "Id")
                item.SetValue(d,p.Id);
                if(item.Name == "Name")
                    item.SetValue(d,p.Name);
            }
            foreach (var item in t1.GetFields())
            {
                if (item.Name.Contains("Description"))
                {
                    item.SetValue(d, p.Description);
                }
            }

.net.core的反射要注意修改 .deps.json 配置文件才可以执行

posted @ 2023-07-25 19:55  学无止境A  阅读(15)  评论(0)    收藏  举报