c#반사 획득 속성

1085 단어
using System.Reflection;
      class Config
       {
            public string encoding { get; set; }
            public string plugins { get; set; }
       } 
        hashtable key config. 
         Hashtable ht = new Hashtable();

        ht.Add("encoding", "utf8");
        ht.Add("plugins", "xxxx");
        Config config = new Config();
        PropertyInfo[] propertys = config.GetType().GetProperties();
        foreach (PropertyInfo property in propertys)
        {
            for (int i = 0; i < ht.Count; i++)
            {
                property.SetValue(config, ht[property.Name].ToString(), null);
            }
        }

 -----------------------------------------------------------------------------------

public class ForeachClass {//////C# 반사 객체 속성/////객체 유형///객체public static void ForeachClassProperties(T model) {Type t=model.GetType(), PropertyInfo[] PropertyList = t.GetProperties();foreach(PropertyInfo item in PropertyList) {string name=item.Name;object value = item.GetValue(모델,null);}}... 하다

좋은 웹페이지 즐겨찾기