【问题标题】:How to get nested level of property class by reflection in .net如何通过.net中的反射获得属性类的嵌套级别
【发布时间】:2013-08-09 01:37:35
【问题描述】:
Class A
{
  public B child {get; set;}
}

Class B
{
   public string childProperty {get; set;}
}

我得到所有财产

 var BType = AType.GetType().GetProperty("child");

我能够获得 A 的“子”属性,但如何从 BType 获得“子属性”?

【问题讨论】:

    标签: c# .net reflection properties nested


    【解决方案1】:

    你可以使用BType.PropertyType获取B类型:

    A AType = new A();
    
    var BType = AType.GetType().GetProperty("child");
    var childPropertyType = BType.PropertyType.GetProperty("childProperty");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      • 2015-10-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多