Is there anything to use, to determine if a type is actually a anonymous type? For example an interface, etc?
The goal is to create something like the following...
//defined like...
public static T Get<T>(this IAnonymous obj, string prop) {
return (T)obj.GetType().GetProperty(prop).GetValue(obj, null);
}
//...
//And then used like...
var something = new { name = "John", age = 25 };
int age = something.Get<int>("age");
Or is that just the beauty of an anonymous type? Nothing to identify it self because it takes a new shape?
Note - I realize that you can write an extension method for the object class, but that seems like a little overkill, in my opinion.