zoukankan      html  css  js  c++  java
  • C#泛型、反射根据对象名获取该类型以及其属性

        //获取名为"MyClass"的类型   
        Type t = Type.GetType("MyClass");   
        //获取"MyClass"的属性   
        PropertyInfo[] properts = t.GetProperties();   
        //根据属性名获取某一属性   
        PropertyInfo p = t.GetProperty("Id");   
        //设置某一属性的值   
        MyClass my = new MyClass();   
        t.setValue(my, 123, null);  

    应用:

        public class BaseClass   
                where T : class, new()   
        {   
                public T Test()   
                {   
                        T t = new T();   
                        PropertyInfo[] properts = t.GetType().GetProperties();   
                        foreach(var item in properts)   
                        {   
                                item.setValue(t, objValue, null);   
                        }   
                        return t;   
                }   
        } 

  • 相关阅读:
    CSS——半透明
    CSS——dispaly、overflow、visibility、opacity
    html——特例
    CSS——◇demo
    html——ico
    JS——函数
    JS——数组
    JS——for
    JS——i++与++i
    JS——三元表达式
  • 原文地址:https://www.cnblogs.com/Byrd/p/2242499.html
Copyright © 2011-2022 走看看