public static TypeReferenceProjection RemoveProjection(TypeReference type)
        {
            if (!type.IsWindowsRuntimeProjection)
            {
                return(null);
            }
            TypeReferenceProjection windowsRuntimeProjection = type.WindowsRuntimeProjection;

            type.WindowsRuntimeProjection = null;
            type.Name      = windowsRuntimeProjection.Name;
            type.Namespace = windowsRuntimeProjection.Namespace;
            type.Scope     = windowsRuntimeProjection.Scope;
            return(windowsRuntimeProjection);
        }
        private static bool ImplementsRedirectedInterface(MemberReference member, out bool disposable)
        {
            disposable = false;
            TypeReference declaringType = member.DeclaringType;
            MetadataToken metadataToken = declaringType.MetadataToken;
            TypeReference typeReference;

            switch (metadataToken.TokenType)
            {
            case TokenType.TypeRef:
                typeReference = declaringType;
                break;

            case TokenType.TypeSpec:
                if (!declaringType.IsGenericInstance)
                {
                    return(false);
                }
                typeReference = ((TypeSpecification)declaringType).ElementType;
                if (typeReference.MetadataType == MetadataType.Class)
                {
                    metadataToken = typeReference.MetadataToken;
                    if (metadataToken.TokenType == TokenType.TypeRef)
                    {
                        break;
                    }
                }
                return(false);

            default:
                return(false);
            }
            TypeReferenceProjection projection = RemoveProjection(typeReference);
            bool result = false;

            if (Projections.TryGetValue(typeReference.Name, out ProjectionInfo projectionInfo) && typeReference.Namespace == projectionInfo.WinRTNamespace)
            {
                disposable = projectionInfo.Disposable;
                result     = true;
            }
            ApplyProjection(typeReference, projection);
            return(result);
        }
        public static void ApplyProjection(TypeReference type, TypeReferenceProjection projection)
        {
            if (projection != null)
            {
                switch (projection.Treatment)
                {
                case TypeReferenceTreatment.SystemDelegate:
                case TypeReferenceTreatment.SystemAttribute:
                    type.Scope = type.Module.Projections.GetAssemblyReference("System.Runtime");
                    break;

                case TypeReferenceTreatment.UseProjectionInfo:
                {
                    ProjectionInfo projectionInfo = Projections[type.Name];
                    type.Name      = projectionInfo.ClrName;
                    type.Namespace = projectionInfo.ClrNamespace;
                    type.Scope     = type.Module.Projections.GetAssemblyReference(projectionInfo.ClrAssembly);
                    break;
                }
                }
                type.WindowsRuntimeProjection = projection;
            }
        }
        public static void ApplyProjection(TypeReference type, TypeReferenceProjection projection)
        {
            if (projection == null)
                return;

            switch (projection.Treatment)
            {
                case TypeReferenceTreatment.SystemDelegate:
                case TypeReferenceTreatment.SystemAttribute:
                    type.Scope = type.Module.Projections.GetAssemblyReference ("System.Runtime");
                    break;

                case TypeReferenceTreatment.UseProjectionInfo:
                    var info = Projections [type.Name];
                    type.Name = info.ClrName;
                    type.Namespace = info.ClrNamespace;
                    type.Scope = type.Module.Projections.GetAssemblyReference (info.ClrAssembly);
                    break;
            }

            type.WindowsRuntimeProjection = projection;
        }