Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are anonymous types in c# accessible through reflection?

As the name of the anonymous type is compiler generated, so is it accessible through reflection?

like image 827
Adeel Avatar asked Feb 10 '10 06:02

Adeel


1 Answers

Yes. As far as the CLR/framework is concerned, they're normal types. In fact, you can do some interesting things with reflection on anonymous types...

The current C# compiler actually creates a generic type though, so that two anonymous types which both just have a "Foo" property of different types will share a generic type, but have different closed types.

like image 181
Jon Skeet Avatar answered Sep 27 '22 22:09

Jon Skeet