C# - 使用泛型进行反射:IList 嵌套集合的问题
我希望能够打印对象属性,但当我遇到 iList 的嵌套集合时遇到了障碍。
foreach (PropertyInformation p in properties)
{
//Ensure IList type, then perform recursive call
if (p.PropertyType.IsGenericType)
{
// recursive call to PrintListProperties<p.type?>((IList)p," ");
}
有人可以提供一些帮助吗?
干杯
KA
I would like to be able to print object properties, and I've hit a snag when I hit nested collections of the iLists.
foreach (PropertyInformation p in properties)
{
//Ensure IList type, then perform recursive call
if (p.PropertyType.IsGenericType)
{
// recursive call to PrintListProperties<p.type?>((IList)p," ");
}
Can anyone please offer some help?
Cheers
KA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
会给你一个类型参数的数组。 (在这种情况下,只有一个元素,即
IList
中的 T)will give you an array of the type arguments. (in ths case, with just one element, the T in
IList<T>
)我只是在这里大声思考。 也许您可以有一个非通用的 PrintListProperties 方法,看起来像这样:
然后,当您遇到嵌套列表时,执行如下操作:
再说一次,还没有测试过这个,但试一试......
I'm just thinking aloud here. Maybe you can have a non generic PrintListProperties method that looks something like this:
Then, when you come across a nested list, do something like this:
Again, haven't tested this, but give it a whirl...