请问:怎么遍历一个类中的所有属性,并把属性键/值对保存到hashtable中呢:hashtable<键,值>。。
请指教~~!谢谢!!~~

解决方案 »

  1.   

    还有相反地,存进去之后相反地怎么遍历hashtable并把每个键的值再赋值给对应属性呢??
    请指教~!谢谢~~~
      

  2.   

    HasTable ht = new HasTable();
    Type type=typeof(ClassName);
    PropertyInfo[] properties = type.GetProperties();
    for (int i = 0; i < properties.Length; i++)
      ht.add(properties[i].Name,properties[i].Attributes);
      

  3.   

    遍历hashtable并把每个键的值再赋值给对应属性
    ClassName c2 = new ClassName();
           
    for (int i = 0; i < propertys.Length;i++ )
    {
          object key = propertys[i].Name;
          propertys[i].SetValue(c2,ht[key], null);
    }