static DmdType?GetEnumerableType(DmdType type)
            {
                if (type.IsArray || type == type.AppDomain.System_String)
                {
                    return(null);
                }

                bool foundEnumerableType = false;
                var  enumerableType      = type.AppDomain.System_Collections_IEnumerable;
                var  enumerableOfTType   = type.AppDomain.System_Collections_Generic_IEnumerable_T;

                switch (GetEnumerableTypeKind(type, enumerableType, enumerableOfTType))
                {
                case EnumerableTypeKind.Enumerable:
                    foundEnumerableType = true;
                    break;

                case EnumerableTypeKind.EnumerableOfT:
                    return(type);
                }

                foreach (var iface in type.GetInterfaces())
                {
                    switch (GetEnumerableTypeKind(iface, enumerableType, enumerableOfTType))
                    {
                    case EnumerableTypeKind.Enumerable:
                        foundEnumerableType = true;
                        break;

                    case EnumerableTypeKind.EnumerableOfT:
                        return(iface);
                    }
                }
                return(foundEnumerableType ? enumerableType : null);
            }
            static bool CheckIsDynamicViewType(DmdType type)
            {
                // Windows Runtime types aren't supported
                if (type.IsWindowsRuntime)
                {
                    return(false);
                }

                // Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView supports COM objects
                if (type.CanCastTo(type.AppDomain.GetWellKnownType(DmdWellKnownType.System___ComObject, isOptional: true)))
                {
                    return(true);
                }

                // Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView supports IDynamicMetaObjectProvider.
                // This type is defined in Microsoft.CSharp which isn't always loaded. That's the reason we don't
                // use a DmdWellKnownType, since when searching for one, the code will check every loaded assembly
                // until the type is found, forcing all lazy-loaded metadata to be loaded. Most of the time it would
                // fail, and thus load all metadata. It's a problem when debugging programs with 100+ loaded assemblies.
                foreach (var iface in type.GetInterfaces())
                {
                    if (iface.DeclaringType is null && iface.MetadataNamespace == "System.Dynamic" && iface.MetadataName == "IDynamicMetaObjectProvider")
                    {
                        return(true);
                    }
                }

                return(false);
            }