开发者

Get all setters from a complex object

I have an object that holds several value types and other objects. I want to use reflect开发者_如何学Goion that would do something for every setter found.

For instance object A has 3 fieds and a children object B that has another 3 fields. So when i have object A i would need to do something for all 6 setters.

Hope i make sense!


The problem is recursive, so you'll have a recursive algorithm:

for your Object A, get its type, get its setters and get its fields. For each field, recursively get the type, the setters, the fields, and so on.

Along the way, call a delegate for each setter found. Or put them in a list and call the delegate at the end.


Use object.GetType().GetProperties() to get an array of all the properties. For each property, you can get the type of the property. You can then, recursively, use GetProperties() on that type, to get the properties.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜