Esempio n. 1
0
        private static bool IsEqualCustomAttributeName(CustomAttributeHandle attributeHandle, MetadataReader metadataReader,
                                                       string attributeNamespace, string attributeName)
        {
            StringHandle namespaceHandle, nameHandle;

            if (!metadataReader.GetAttributeNamespaceAndName(attributeHandle, out namespaceHandle, out nameHandle))
            {
                return(false);
            }

            return(metadataReader.StringComparer.Equals(namespaceHandle, attributeNamespace) &&
                   metadataReader.StringComparer.Equals(nameHandle, attributeName));
        }
Esempio n. 2
0
        public static CustomAttributeHandle GetCustomAttributeHandle(this MetadataReader metadataReader, CustomAttributeHandleCollection customAttributes,
                                                                     string attributeNamespace, string attributeName)
        {
            foreach (var attributeHandle in customAttributes)
            {
                StringHandle namespaceHandle, nameHandle;
                if (!metadataReader.GetAttributeNamespaceAndName(attributeHandle, out namespaceHandle, out nameHandle))
                {
                    continue;
                }

                if (metadataReader.StringComparer.Equals(namespaceHandle, attributeNamespace) &&
                    metadataReader.StringComparer.Equals(nameHandle, attributeName))
                {
                    return(attributeHandle);
                }
            }

            return(default(CustomAttributeHandle));
        }
Esempio n. 3
0
        public static bool HasCustomAttribute(this MetadataReader metadataReader, CustomAttributeHandleCollection customAttributes,
                                              string attributeNamespace, string attributeName)
        {
            foreach (var attributeHandle in customAttributes)
            {
                ConstantStringValueHandle nameHandle;
                string namespaceName;
                if (!metadataReader.GetAttributeNamespaceAndName(attributeHandle, out namespaceName, out nameHandle))
                {
                    continue;
                }

                if (namespaceName.Equals(attributeNamespace) &&
                    nameHandle.StringEquals(attributeName, metadataReader))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets a value indicating whether '<paramref name="module"/>' is a framework assembly.
        /// </summary>
        public static bool IsFrameworkAssembly(EcmaModule module)
        {
            MetadataReader reader = module.MetadataReader;

            // We look for [assembly:AssemblyMetadata(".NETFrameworkAssembly", "")]

            foreach (CustomAttributeHandle attributeHandle in reader.GetAssemblyDefinition().GetCustomAttributes())
            {
                if (!reader.GetAttributeNamespaceAndName(attributeHandle, out StringHandle namespaceHandle, out StringHandle nameHandle))
                {
                    continue;
                }

                if (!reader.StringComparer.Equals(namespaceHandle, "System.Reflection") ||
                    !reader.StringComparer.Equals(nameHandle, "AssemblyMetadataAttribute"))
                {
                    continue;
                }

                var             attributeTypeProvider            = new CustomAttributeTypeProvider(module);
                CustomAttribute attribute                        = reader.GetCustomAttribute(attributeHandle);
                CustomAttributeValue <TypeDesc> decodedAttribute = attribute.DecodeValue(attributeTypeProvider);

                if (decodedAttribute.FixedArguments.Length != 2)
                {
                    continue;
                }

                if (decodedAttribute.FixedArguments[0].Value is string s && s == ".NETFrameworkAssembly")
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 5
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            if ((mask & TypeFlags.CategoryMask) != 0)
            {
                TypeDesc baseType = this.BaseType;

                if (baseType != null && baseType.IsWellKnownType(WellKnownType.ValueType))
                {
                    flags |= TypeFlags.ValueType;
                }
                else
                if (baseType != null && baseType.IsWellKnownType(WellKnownType.Enum))
                {
                    flags |= TypeFlags.Enum;
                }
                else
                {
                    if ((_typeDefinition.Attributes & TypeAttributes.Interface) != 0)
                        flags |= TypeFlags.Interface;
                    else
                        flags |= TypeFlags.Class;
                }

                // All other cases are handled during TypeSystemContext intitialization
            }

            if ((mask & TypeFlags.HasGenericVarianceComputed) != 0)
            {
                flags |= TypeFlags.HasGenericVarianceComputed;

                foreach (GenericParameterDesc genericParam in Instantiation)
                {
                    if (genericParam.Variance != GenericVariance.None)
                    {
                        flags |= TypeFlags.HasGenericVariance;
                        break;
                    }
                }
            }

            if ((mask & TypeFlags.HasFinalizerComputed) != 0)
            {
                flags |= TypeFlags.HasFinalizerComputed;

                if (GetFinalizer() != null)
                    flags |= TypeFlags.HasFinalizer;
            }

            if ((mask & TypeFlags.AttributeCacheComputed) != 0)
            {
                MetadataReader reader = MetadataReader;
                MetadataStringComparer stringComparer = reader.StringComparer;
                bool isValueType = IsValueType;

                flags |= TypeFlags.AttributeCacheComputed;

                foreach (CustomAttributeHandle attributeHandle in _typeDefinition.GetCustomAttributes())
                {
                    if (MetadataReader.GetAttributeNamespaceAndName(attributeHandle, out StringHandle namespaceHandle, out StringHandle nameHandle))
                    {
                        if (isValueType &&
                            stringComparer.Equals(nameHandle, "IsByRefLikeAttribute") &&
                            stringComparer.Equals(namespaceHandle, "System.Runtime.CompilerServices"))
                            flags |= TypeFlags.IsByRefLike;

                        if (stringComparer.Equals(nameHandle, "IntrinsicAttribute") &&
                            stringComparer.Equals(namespaceHandle, "System.Runtime.CompilerServices"))
                            flags |= TypeFlags.IsIntrinsic;
                    }
                }
            }

            return flags;
        }