Esempio n. 1
0
        public static TypeDefinitionProjection RemoveProjection(TypeDefinition type)
        {
            if (!type.IsWindowsRuntimeProjection)
            {
                return(null);
            }
            TypeDefinitionProjection windowsRuntimeProjection = type.WindowsRuntimeProjection;

            type.WindowsRuntimeProjection = null;
            type.Attributes = windowsRuntimeProjection.Attributes;
            type.Name       = windowsRuntimeProjection.Name;
            return(windowsRuntimeProjection);
        }
Esempio n. 2
0
        public static void ApplyProjection(TypeDefinition type, TypeDefinitionProjection projection)
        {
            if (projection == null)
            {
                return;
            }

            var treatment = projection.Treatment;

            switch (treatment & TypeDefinitionTreatment.KindMask)
            {
            case TypeDefinitionTreatment.NormalType:
                type.Attributes |= TypeAttributes.WindowsRuntime | TypeAttributes.Import;
                break;

            case TypeDefinitionTreatment.NormalAttribute:
                type.Attributes |= TypeAttributes.WindowsRuntime | TypeAttributes.Sealed;
                break;

            case TypeDefinitionTreatment.UnmangleWindowsRuntimeName:
                type.Attributes = type.Attributes & ~TypeAttributes.SpecialName | TypeAttributes.Public;
                type.Name       = type.Name.Substring("<CLR>".Length);
                break;

            case TypeDefinitionTreatment.PrefixWindowsRuntimeName:
                type.Attributes = type.Attributes & ~TypeAttributes.Public | TypeAttributes.Import;
                type.Name       = "<WinRT>" + type.Name;
                break;

            case TypeDefinitionTreatment.RedirectToClrType:
                type.Attributes = type.Attributes & ~TypeAttributes.Public | TypeAttributes.Import;
                break;

            case TypeDefinitionTreatment.RedirectToClrAttribute:
                type.Attributes = type.Attributes & ~TypeAttributes.Public;
                break;
            }

            if ((treatment & TypeDefinitionTreatment.Abstract) != 0)
            {
                type.Attributes |= TypeAttributes.Abstract;
            }

            if ((treatment & TypeDefinitionTreatment.Internal) != 0)
            {
                type.Attributes &= ~TypeAttributes.Public;
            }

            type.WindowsRuntimeProjection = projection;
        }
Esempio n. 3
0
        public static void ApplyProjection(TypeDefinition type, TypeDefinitionProjection projection)
        {
            if (projection != null)
            {
                TypeDefinitionTreatment treatment = projection.Treatment;
                switch (treatment & TypeDefinitionTreatment.KindMask)
                {
                case TypeDefinitionTreatment.NormalType:
                    type.Attributes |= (TypeAttributes.Import | TypeAttributes.WindowsRuntime);
                    break;

                case TypeDefinitionTreatment.NormalAttribute:
                    type.Attributes |= (TypeAttributes.Sealed | TypeAttributes.WindowsRuntime);
                    break;

                case TypeDefinitionTreatment.UnmangleWindowsRuntimeName:
                    type.Attributes = (TypeAttributes)(((int)type.Attributes & -1025) | 1);
                    type.Name       = type.Name.Substring("<CLR>".Length);
                    break;

                case TypeDefinitionTreatment.PrefixWindowsRuntimeName:
                    type.Attributes = (TypeAttributes)(((int)type.Attributes & -2) | 0x1000);
                    type.Name       = "<WinRT>" + type.Name;
                    break;

                case TypeDefinitionTreatment.RedirectToClrType:
                    type.Attributes = (TypeAttributes)(((int)type.Attributes & -2) | 0x1000);
                    break;

                case TypeDefinitionTreatment.RedirectToClrAttribute:
                    type.Attributes &= ~TypeAttributes.Public;
                    break;
                }
                if ((treatment & TypeDefinitionTreatment.Abstract) != 0)
                {
                    type.Attributes |= TypeAttributes.Abstract;
                }
                if ((treatment & TypeDefinitionTreatment.Internal) != 0)
                {
                    type.Attributes &= ~TypeAttributes.Public;
                }
                type.WindowsRuntimeProjection = projection;
            }
        }
Esempio n. 4
0
        public static void ApplyProjection(TypeDefinition type, TypeDefinitionProjection projection)
        {
            if (projection == null)
            {
                return;
            }

            var treatment = projection.Treatment;

            switch (treatment & TypeDefinitionTreatment.KindMask)
            {
            case TypeDefinitionTreatment.NormalType:
                type.Attributes |= TypeAttributes.WindowsRuntime | TypeAttributes.Import;
                break;

            case TypeDefinitionTreatment.NormalAttribute:
                type.Attributes |= TypeAttributes.WindowsRuntime | TypeAttributes.Sealed;
                break;

            case TypeDefinitionTreatment.UnmangleWindowsRuntimeName:
                type.Attributes = type.Attributes & ~TypeAttributes.SpecialName | TypeAttributes.Public;
                type.Name       = type.Name.Substring("<CLR>".Length);
                break;

            case TypeDefinitionTreatment.PrefixWindowsRuntimeName:
                type.Attributes = type.Attributes & ~TypeAttributes.Public | TypeAttributes.Import;
                type.Name       = "<WinRT>" + type.Name;
                break;

            case TypeDefinitionTreatment.RedirectToClrType:
                type.Attributes = type.Attributes & ~TypeAttributes.Public | TypeAttributes.Import;
                break;

            case TypeDefinitionTreatment.RedirectToClrAttribute:
                type.Attributes = type.Attributes & ~TypeAttributes.Public;
                break;

            case TypeDefinitionTreatment.RedirectImplementedMethods: {
                type.Attributes |= TypeAttributes.WindowsRuntime | TypeAttributes.Import;

                foreach (var redirectedInterfacePair in projection.RedirectedInterfaces)
                {
                    type.Interfaces.Add(redirectedInterfacePair.Value);

                    foreach (var customAttribute in redirectedInterfacePair.Key.CustomAttributes)
                    {
                        redirectedInterfacePair.Value.CustomAttributes.Add(customAttribute);
                    }

                    redirectedInterfacePair.Key.CustomAttributes.Clear();

                    foreach (var method in type.Methods)
                    {
                        foreach (var @override in method.Overrides)
                        {
                            if (TypeReferenceEqualityComparer.AreEqual(@override.DeclaringType, redirectedInterfacePair.Key.InterfaceType))
                            {
                                @override.DeclaringType = redirectedInterfacePair.Value.InterfaceType;
                            }
                        }
                    }
                }

                foreach (var method in projection.RedirectedMethods)
                {
                    type.Methods.Add(method);
                }
            }
            break;
            }

            if ((treatment & TypeDefinitionTreatment.Abstract) != 0)
            {
                type.Attributes |= TypeAttributes.Abstract;
            }

            if ((treatment & TypeDefinitionTreatment.Internal) != 0)
            {
                type.Attributes &= ~TypeAttributes.Public;
            }

            type.WindowsRuntimeProjection = projection;
        }
        public static void ApplyProjection(TypeDefinition type, TypeDefinitionProjection projection)
        {
            if (projection == null)
                return;

            var treatment = projection.Treatment;

            switch (treatment & TypeDefinitionTreatment.KindMask) {
            case TypeDefinitionTreatment.NormalType:
                type.Attributes |= TypeAttributes.WindowsRuntime | TypeAttributes.Import;
                break;

            case TypeDefinitionTreatment.NormalAttribute:
                type.Attributes |= TypeAttributes.WindowsRuntime | TypeAttributes.Sealed;
                break;

            case TypeDefinitionTreatment.UnmangleWindowsRuntimeName:
                type.Attributes = type.Attributes & ~TypeAttributes.SpecialName | TypeAttributes.Public;
                type.Name = type.Name.Substring ("<CLR>".Length);
                break;

            case TypeDefinitionTreatment.PrefixWindowsRuntimeName:
                type.Attributes = type.Attributes & ~TypeAttributes.Public | TypeAttributes.Import;
                type.Name = "<WinRT>" + type.Name;
                break;

            case TypeDefinitionTreatment.RedirectToClrType:
                type.Attributes = type.Attributes & ~TypeAttributes.Public | TypeAttributes.Import;
                break;

            case TypeDefinitionTreatment.RedirectToClrAttribute:
                type.Attributes = type.Attributes & ~TypeAttributes.Public;
                break;

            case TypeDefinitionTreatment.RedirectImplementedMethods: {
                    type.Attributes |= TypeAttributes.WindowsRuntime | TypeAttributes.Import;

                    foreach (var redirectedInterfacePair in projection.RedirectedInterfaces) {
                        type.Interfaces.Add (redirectedInterfacePair.Value);

                        foreach (var customAttribute in redirectedInterfacePair.Key.CustomAttributes)
                            redirectedInterfacePair.Value.CustomAttributes.Add (customAttribute);

                        redirectedInterfacePair.Key.CustomAttributes.Clear ();

                        foreach (var method in type.Methods) {
                            foreach (var @override in method.Overrides) {
                                if (TypeReferenceEqualityComparer.AreEqual (@override.DeclaringType, redirectedInterfacePair.Key.InterfaceType)) {
                                    @override.DeclaringType = redirectedInterfacePair.Value.InterfaceType;
                                }
                            }
                        }
                    }

                    foreach (var method in projection.RedirectedMethods) {
                        type.Methods.Add (method);
                    }
                }
                break;
            }

            if ((treatment & TypeDefinitionTreatment.Abstract) != 0)
                type.Attributes |= TypeAttributes.Abstract;

            if ((treatment & TypeDefinitionTreatment.Internal) != 0)
                type.Attributes &= ~TypeAttributes.Public;

            type.WindowsRuntimeProjection = projection;
        }