天天看點

關于反射中如何得到被反射執行個體的屬性值

在反射應用中,常常需要涉及一個問題,被反射執行個體中的屬性值如何獲得。

用GetValue()

實際的例子是采用如下方式:

foreach (var item in List < T > listopo)
{
   foreach (FieldInfo info in item.GetType().GetValue(item))
   {
      if (info.FieldType.name == "ooo")
       {
          object cc = info.GetValue(item);
          if (cc == aiData & cc is listopo)
             {
               str = item.strname;
             }
        }
   }
}

           

其中listopo是一個list類

每個item是一個複雜的類,裡面含有多種屬性、方法、string等

并且有多個同一屬性的public項

好累啊!

繼續閱讀