小编Way*_*yne的帖子

递归获取对象的属性和子属性

好吧,首先我觉得这很容易,也许就是这样,我太累了 - 但这就是我想做的事情.说我有以下对象:

public class Container
{
     public string Name { get; set; }
     public List<Address> Addresses { get; set; }
}
public class Address
{
     public string AddressLine1 { get; set; }
     public string AddressLine2 { get; set; }
     public List<Telephone> Telephones { get; set; }
}
public class Telephone
{
     public string CellPhone { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我需要做的是,将容器属性名称'flatten'到一个字符串(包括所有子属性和子属性的子属性),看起来像这样:

Container.Name, Container.Addresses.AddressLine1, Container.Addresses.AddressLine2, Container.Addresses.Telephones.CellPhone
Run Code Online (Sandbox Code Playgroud)

这有任何意义吗?我似乎无法将它包裹在我的脑海里.

c# reflection collections

13
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

collections ×1

reflection ×1