Shailesh
Shailesh

Reputation: 101

List<dynamic> does not return structure

I got a public property of List<dynamic> type.

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. 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.

Upvotes: 0

Views: 71

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 157098

Well, that is obviously true. dynamic properties are evaluated at run time. 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.)

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.

Upvotes: 1

Related Questions