// // Lightweight check to see if a custom attribute's is of a well-known type. // // This check performs without instantating the Type object and bloating memory usage. On the flip side, // it doesn't check on whether the type is defined in a paricular assembly. The desktop CLR typically doesn't // check this either so this is useful from a compat persective as well. // public static bool IsCustomAttributeOfType(this CustomAttributeHandle customAttributeHandle, MetadataReader reader, String ns, String name) { String[] namespaceParts = ns.Split('.'); Handle typeHandle = customAttributeHandle.GetCustomAttribute(reader).GetAttributeTypeHandle(reader); HandleType handleType = typeHandle.HandleType; if (handleType == HandleType.TypeDefinition) { TypeDefinition typeDefinition = typeHandle.ToTypeDefinitionHandle(reader).GetTypeDefinition(reader); if (!typeDefinition.Name.StringEquals(name, reader)) { return(false); } NamespaceDefinitionHandle nsHandle = typeDefinition.NamespaceDefinition; int idx = namespaceParts.Length; while (idx-- != 0) { String namespacePart = namespaceParts[idx]; NamespaceDefinition namespaceDefinition = nsHandle.GetNamespaceDefinition(reader); if (!namespaceDefinition.Name.StringOrNullEquals(namespacePart, reader)) { return(false); } if (!namespaceDefinition.ParentScopeOrNamespace.IsNamespaceDefinitionHandle(reader)) { return(false); } nsHandle = namespaceDefinition.ParentScopeOrNamespace.ToNamespaceDefinitionHandle(reader); } if (!nsHandle.GetNamespaceDefinition(reader).Name.StringOrNullEquals(null, reader)) { return(false); } return(true); } else if (handleType == HandleType.TypeReference) { TypeReference typeReference = typeHandle.ToTypeReferenceHandle(reader).GetTypeReference(reader); if (!typeReference.TypeName.StringEquals(name, reader)) { return(false); } if (!typeReference.ParentNamespaceOrType.IsNamespaceReferenceHandle(reader)) { return(false); } NamespaceReferenceHandle nsHandle = typeReference.ParentNamespaceOrType.ToNamespaceReferenceHandle(reader); int idx = namespaceParts.Length; while (idx-- != 0) { String namespacePart = namespaceParts[idx]; NamespaceReference namespaceReference = nsHandle.GetNamespaceReference(reader); if (!namespaceReference.Name.StringOrNullEquals(namespacePart, reader)) { return(false); } if (!namespaceReference.ParentScopeOrNamespace.IsNamespaceReferenceHandle(reader)) { return(false); } nsHandle = namespaceReference.ParentScopeOrNamespace.ToNamespaceReferenceHandle(reader); } if (!nsHandle.GetNamespaceReference(reader).Name.StringOrNullEquals(null, reader)) { return(false); } return(true); } else { throw new NotSupportedException(); } }
internal RuntimeNormalCustomAttributeData(ReflectionDomain reflectionDomain, MetadataReader reader, CustomAttributeHandle customAttributeHandle) { _reflectionDomain = reflectionDomain; _reader = reader; _customAttribute = customAttributeHandle.GetCustomAttribute(reader); }
internal RuntimeNormalCustomAttributeData(MetadataReader reader, CustomAttributeHandle customAttributeHandle) { _reader = reader; _customAttribute = customAttributeHandle.GetCustomAttribute(reader); }
internal EcmaCustomAttributeData(CustomAttributeHandle handle, EcmaModule module) { _handle = handle; _module = module; _neverAccessThisExceptThroughCustomAttributeProperty = handle.GetCustomAttribute(Reader); }
internal NativeFormatCustomAttributeData(MetadataReader reader, CustomAttributeHandle customAttributeHandle) { _reader = reader; _customAttribute = customAttributeHandle.GetCustomAttribute(reader); }