<p>Is there anything to use, to determine if a type is actually a anonymous type? For example an interface, etc?</p>

<p>The goal is to create something like the following...</p>

<pre><code>//defined like...
public static T Get&lt;T&gt;(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&lt;int&gt;("age");
</code></pre>

<p>Or is that just the beauty of an anonymous type? Nothing to identify it self because it takes a new shape?</p>

<p><strong>Note</strong> - I realize that you can write an extension method for the <strong>object</strong> class, but that seems like a little overkill, in my opinion.</p>

As I recall, there is a
```
[CompilerGenerated]
```
marker... 2 secs
Plus the name will be freaky, and it will be a generic type ;-p
Actually, for a "get" etc I would probably just use a static (non-extension) method.
If you just want a way to get the value from an instance of an anon-type (at a later point in time), a lambda is probably the best option - note you need a few tricks to pull this off:
```
```
static void Main()
    {
        var foo = new { name = "John", age = 25 };
        var func = Get(foo, x => x.age);
        var bar = new { name = "Marc", age = 30 };
        int age = func(bar);
    }
    // template here is just for type inference...
    static Func<TSource, TValue> Get<TSource, TValue>(
        TSource template, Func<TSource, TValue> lambda)
    {
        return lambda;
    }
```
```
(edit re the comment) There definitely
is
this attribute:
```
```
var foo = new { A = "B" };
        Type type = foo.GetType();

        CompilerGeneratedAttribute attrib = (CompilerGeneratedAttribute) Attribute.GetCustomAttribute(
            type, typeof(CompilerGeneratedAttribute)); // non-null, therefore is compiler-generated
```
```