How can I get the value of a string property via Reflection?

前端 未结 9 1587
日久生厌
日久生厌 2020-11-30 04:46
public class Foo
{
   public string Bar {get; set;}
}

How do I get the value of Bar, a string property, via reflection? The following code will thr

9条回答
  •  一生所求
    2020-11-30 05:42

    PropertyInfo propInfo = f.GetType().GetProperty("Bar");
    object[] obRetVal = new Object[0];
    string bar = propInfo.GetValue(f,obRetVal) as string;
    

提交回复
热议问题