Exemplo n.º 1
0
        public override void GetTypeRefProps(
            TypeReferenceHandle typeRef,
            out string name,
            out string @namespace,
            out MetadataToken resolutionScope)
        {
            base.GetTypeRefProps(typeRef, out name, out @namespace, out resolutionScope);

// TODO (tomat): disable the warning temporarily until we move this code to the metadata reader
#pragma warning disable 618 // obsolete warning reported when RowIds are used
            uint   assemblyRefOffset;
            string clrName, clrNamespace;
            if (WinRTProjectedTypes.ResolveWinRTTypeReference(name, @namespace, out clrName, out clrNamespace, out assemblyRefOffset))
            {
                name       = clrName;
                @namespace = clrNamespace;
                uint assemblyRefRid = this.winMdStartIndex + assemblyRefOffset + 1;
                resolutionScope = AssemblyReferenceHandle.FromRowId(assemblyRefRid);
            }
            else if (GetTypeRefTreatment(typeRef) != TypeRefTreatment.None)
            {
                uint assemblyRefRid = this.winMdStartIndex + (uint)WinMdAssembliesOffsets.SystemRuntime + 1;
                resolutionScope = AssemblyReferenceHandle.FromRowId(assemblyRefRid);
            }
#pragma warning restore 618 // obsolete warning reported when RowIds are used
        }
Exemplo n.º 2
0
        private TypeDefTreatment GetTypeDefTreatment(
            TypeHandle typeDef,
            TypeAttributes flags,
            string name,
            string namespaceName,
            MetadataToken extends)
        {
            TypeDefTreatment treatment;

            // Does the type def have the WindowsRuntime bit set?
            if (flags.IsWindowsRuntime())
            {
                if (scenario == WinMDScenario.NormalWinMD)
                {
                    treatment = WinRTProjectedTypes.GetTypeDefinitionTreatment(name, namespaceName);
                    if (treatment != TypeDefTreatment.None)
                    {
                        return(treatment);
                    }

                    // Is this an attribute?
                    if (extends.HandleType == HandleType.TypeReference && GetTypeRefTreatment((TypeReferenceHandle)extends) == TypeRefTreatment.SystemAttribute)
                    {
                        treatment = TypeDefTreatment.NormalAttribute;
                    }
                    else
                    {
                        treatment = TypeDefTreatment.NormalNonAttribute;
                    }
                }
                else if (scenario == WinMDScenario.WinMDExp && !flags.IsNested() && flags.IsPublic() && flags.IsSpecialName())
                {
                    treatment = TypeDefTreatment.PrefixWinRTName;
                }
                else
                {
                    treatment = TypeDefTreatment.None;
                }

                // Scan through Custom Attributes on type, looking for interesting bits. We only
                // need to do this for RuntimeClasses
                if (treatment == TypeDefTreatment.PrefixWinRTName || treatment == TypeDefTreatment.NormalNonAttribute)
                {
                    if (!flags.IsInterface() && HasAttribute(typeDef, "Windows.UI.Xaml", "TreatAsAbstractComposableClassAttribute"))
                    {
                        treatment |= TypeDefTreatment.MarkAbstractFlag;
                    }
                }
            }
            else if (this.scenario == WinMDScenario.WinMDExp && IsClrImplementationType(name, flags))
            {
                treatment = TypeDefTreatment.UnmangleWinRTName;
            }
            else
            {
                treatment = TypeDefTreatment.None;
            }

            return(treatment);
        }
Exemplo n.º 3
0
        /// <summary>
        /// We want to know if a given method implements a redirected interface.
        /// For example, if we are given the method RemoveAt on a class "A"
        /// which implements the IVector interface (which is redirected
        /// to IList in .NET) then this method would return true. The most
        /// likely reason why we would want to know this is that we wish to hide
        /// (mark private) all methods which implement methods on a redirected
        /// interface.
        /// </summary>
        /// <param name="memberRef">The declaration token for the method</param>
        /// <param name="isIDisposable">
        /// Returns true if the redirected interface is <see cref="IDisposable"/>.
        /// </param>
        /// <returns>True if the method implements a method on a redirected interface.
        /// False otherwise.</returns>
        private bool ImplementsRedirectedInterface(MemberReferenceHandle memberRef, out bool isIDisposable)
        {
            isIDisposable = false;

            MetadataToken parent = peFileReader.GetMemberReference((MemberReferenceHandle)memberRef).Parent;

            TypeReferenceHandle typeRef;

            if (parent.HandleType == HandleType.TypeReference)
            {
                typeRef = (TypeReferenceHandle)parent;
            }
            else if (parent.HandleType == HandleType.TypeSpecification)
            {
                BlobHandle  blob     = peFileReader.GetTypeSpecification((TypeSpecificationHandle)parent);
                MemoryBlock sigBlock = peFileReader.BlobStream.GetMemoryBlockAt(blob);

                if (sigBlock.Length < 2)
                {
                    return(false);
                }

                MemoryReader sig = new MemoryReader(sigBlock);

                if (sig.ReadByte() != (byte)CorElementType.ELEMENT_TYPE_GENERICINST ||
                    sig.ReadByte() != (byte)CorElementType.ELEMENT_TYPE_CLASS)
                {
                    return(false);
                }

                MetadataToken token = SignatureHelpers.DecodeToken(ref sig);

                if (token.HandleType != HandleType.TypeReference)
                {
                    return(false);
                }

                typeRef = (TypeReferenceHandle)token;
            }
            else
            {
                return(false);
            }

            TypeReference reference = peFileReader.GetTypeReference(typeRef);

            if (reference.Namespace.IsNil)
            {
                return(false);
            }

            string name       = peFileReader.StringStream[reference.Name];
            string @namespace = peFileReader.StringStream[reference.Namespace];

            return(WinRTProjectedTypes.IsWinRTTypeReference(name, @namespace, out isIDisposable));
        }