Jayrock.Json.Conversion.CustomTypeDescriptor.LikeAnonymousClass C# (CSharp) Method

LikeAnonymousClass() static private method

Forward-compatible way to see if the given type is an anonymous class (introduced since C# 3.0).
There is no sure shot method so we have rely to rely on a heuristic approach by looking for a few known characteristics. Note also that we take a "duck" approach to look for the CompilerGenerated attribute under .NET Framework 1.x, which does not seem like an appaling idea considering that the C# compiler does the same with ExtensionAttribute when it comes to extension methods.
static private LikeAnonymousClass ( Type type ) : bool
type System.Type
return bool
        internal static bool LikeAnonymousClass(Type type)
        {
            Debug.Assert(type != null);

            return type.IsNotPublic && type.IsClass && type.IsSealed
                && type.GetConstructor(Type.EmptyTypes) == null
            #if NET_1_0 || NET_1_1
                && AnyObjectByTypeName(type.GetCustomAttributes(false),
                       "System.Runtime.CompilerServices.CompilerGeneratedAttribute")
            #else
                && type.IsGenericType
                && type.IsDefined(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false)
            #endif
                ;
        }