views:

26

answers:

0

Possible Duplicates:
How to identify anonymous methods in System.Reflection
Anonymous Types - Are there any distingushing characteristics?

The CLR doesn't know an anonymous type from a 'normal' type - that's something the compiler handles. How am I supposed to tell that a type found during reflection is anonymous?

public static class TypeExtensions
{
    public static bool IsAnonymous(this Type type)
    {
        return type.Name.StartsWith("<")
            || string.IsNullOrEmpty(type.Namespace)
            || type.Namespace.StartsWith("<");
    }
}

I am open to better suggestions :)