Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to restrict a generic type parameter to an anonymous type?

Is there any way to restrict a generic type parameter to an anonymous type in C# 4.0? Or is where T: class the closest I will come ?

like image 743
smartcaveman Avatar asked May 11 '11 13:05

smartcaveman


1 Answers

No, there are no such constraints in C#. You could add an execution-time check to validate that the type has the characteristics of an anonymous type though.

like image 98
Jon Skeet Avatar answered Sep 20 '22 03:09

Jon Skeet