简体   繁体   English

名单 <dynamic> 不返回结构

[英]List<dynamic> does not return structure

I got a public property of List<dynamic> type. 我得到了List <dynamic>类型的公共属性。

This property is getting populated with same type of objects in the list. 此属性将使用列表中相同类型的对象填充。 I am using a third party reporting tool to design a report by data returned by this property. 我正在使用第三方报告工具通过此属性返回的数据来设计报告。

When the List object contains data, I am able to see the required properties/structure to design the report. 当List对象包含数据时,我可以看到设计报告所需的属性/结构。 Whereas when there is no data I do not see any properties to create the report layout. 而当没有数据时,我看不到任何用于创建报告布局的属性。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thanks for your help. 谢谢你的帮助。

Well, that is obviously true. 好吧,那显然是真的。 dynamic properties are evaluated at run time. dynamic属性在运行时评估。 If there is no data to show, there is no way to know what type of object, struct or anything else would actually go in there. 如果没有要显示的数据,则无法知道实际上将放入哪种类型的对象,结构或其他任何对象。 So reflection is not able to determine anything about the type at that moment. 因此,反射此时无法确定有关该类型的任何信息。 (I don't have to say that using reflection on dynamic types is dangerous to start with, since the type can change at any time without any warning.) (我不必说对dynamic类型使用反射是很危险的,因为dynamic类型可以随时更改而不会发出任何警告。)

The solution is to ensure there is always data so reflection can determine the types on the data provided, or preferably don't use dynamic at all. 解决方案是确保始终有数据,以便反射可以确定所提供数据的类型,或者最好根本不使用dynamic数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM