internal CustomAttributeValueTreatment CalculateCustomAttributeValueTreatment(CustomAttributeHandle handle) { Debug.Assert(_metadataKind != MetadataKind.Ecma335); var parent = CustomAttributeTable.GetParent(handle); // Check for Windows.Foundation.Metadata.AttributeUsageAttribute. // WinMD rules: // - The attribute is only applicable on TypeDefs. // - Constructor must be a MemberRef with TypeRef. if (!IsWindowsAttributeUsageAttribute(parent, handle)) { return(CustomAttributeValueTreatment.None); } var targetTypeDef = (TypeDefinitionHandle)parent; if (StringStream.EqualsRaw(TypeDefTable.GetNamespace(targetTypeDef), "Windows.Foundation.Metadata")) { if (StringStream.EqualsRaw(TypeDefTable.GetName(targetTypeDef), "VersionAttribute")) { return(CustomAttributeValueTreatment.AttributeUsageVersionAttribute); } if (StringStream.EqualsRaw(TypeDefTable.GetName(targetTypeDef), "DeprecatedAttribute")) { return(CustomAttributeValueTreatment.AttributeUsageDeprecatedAttribute); } } bool allowMultiple = HasAttribute(targetTypeDef, "Windows.Foundation.Metadata", "AllowMultipleAttribute"); return(allowMultiple ? CustomAttributeValueTreatment.AttributeUsageAllowMultiple : CustomAttributeValueTreatment.AttributeUsageAllowSingle); }
private bool IsWindowsAttributeUsageAttribute(EntityHandle targetType, CustomAttributeHandle attributeHandle) { // Check for Windows.Foundation.Metadata.AttributeUsageAttribute. // WinMD rules: // - The attribute is only applicable on TypeDefs. // - Constructor must be a MemberRef with TypeRef. if (targetType.Kind != HandleKind.TypeDefinition) { return(false); } var attributeCtor = CustomAttributeTable.GetConstructor(attributeHandle); if (attributeCtor.Kind != HandleKind.MemberReference) { return(false); } var attributeType = MemberRefTable.GetClass((MemberReferenceHandle)attributeCtor); if (attributeType.Kind != HandleKind.TypeReference) { return(false); } var attributeTypeRef = (TypeReferenceHandle)attributeType; return(StringStream.EqualsRaw(TypeRefTable.GetName(attributeTypeRef), "AttributeUsageAttribute") && StringStream.EqualsRaw(TypeRefTable.GetNamespace(attributeTypeRef), "Windows.Foundation.Metadata")); }
private TypeDefTreatment GetWellKnownTypeDefinitionTreatment(TypeDefinitionHandle typeDef) { InitializeProjectedTypes(); StringHandle name = TypeDefTable.GetName(typeDef); int index = StringStream.BinarySearchRaw(s_projectedTypeNames, name); if (index < 0) { return(TypeDefTreatment.None); } StringHandle namespaceName = TypeDefTable.GetNamespace(typeDef); if (StringStream.EqualsRaw(namespaceName, StringStream.GetVirtualValue(s_projectionInfos[index].ClrNamespace))) { return(s_projectionInfos[index].Treatment); } // TODO: we can avoid this comparison if info.DotNetNamespace == info.WinRtNamespace if (StringStream.EqualsRaw(namespaceName, s_projectionInfos[index].WinRTNamespace)) { return(s_projectionInfos[index].Treatment | TypeDefTreatment.MarkInternalFlag); } return(TypeDefTreatment.None); }
private MethodDefTreatment GetMethodTreatmentFromCustomAttributes(MethodDefinitionHandle methodDef) { MethodDefTreatment treatment = 0; foreach (var caHandle in GetCustomAttributes(methodDef)) { StringHandle namespaceHandle, nameHandle; if (!GetAttributeTypeNameRaw(caHandle, out namespaceHandle, out nameHandle)) { continue; } Debug.Assert(!namespaceHandle.IsVirtual && !nameHandle.IsVirtual); if (StringStream.EqualsRaw(namespaceHandle, "Windows.UI.Xaml")) { if (StringStream.EqualsRaw(nameHandle, "TreatAsPublicMethodAttribute")) { treatment |= MethodDefTreatment.MarkPublicFlag; } if (StringStream.EqualsRaw(nameHandle, "TreatAsAbstractMethodAttribute")) { treatment |= MethodDefTreatment.MarkAbstractFlag; } } } return(treatment); }
private bool NeedsWinRTPrefix(TypeAttributes flags, EntityHandle extends) { if ((flags & (TypeAttributes.VisibilityMask | TypeAttributes.Interface)) != TypeAttributes.Public) { return(false); } if (extends.Kind != HandleKind.TypeReference) { return(false); } // Check if the type is a delegate, struct, or attribute TypeReferenceHandle extendsRefHandle = (TypeReferenceHandle)extends; if (StringStream.EqualsRaw(TypeRefTable.GetNamespace(extendsRefHandle), "System")) { StringHandle nameHandle = TypeRefTable.GetName(extendsRefHandle); if (StringStream.EqualsRaw(nameHandle, "MulticastDelegate") || StringStream.EqualsRaw(nameHandle, "ValueType") || StringStream.EqualsRaw(nameHandle, "Attribute")) { return(false); } } return(true); }
private int FindMscorlibAssemblyRefNoProjection() { for (int i = 1; i <= AssemblyRefTable.NumberOfNonVirtualRows; i++) { if (StringStream.EqualsRaw(AssemblyRefTable.GetName(i), "mscorlib")) { return(i); } } throw new BadImageFormatException(SR.WinMDMissingMscorlibRef); }
private int GetProjectionIndexForTypeReference(TypeReferenceHandle typeRef, out bool isIDisposable) { InitializeProjectedTypes(); int index = StringStream.BinarySearchRaw(s_projectedTypeNames, TypeRefTable.GetName(typeRef)); if (index >= 0 && StringStream.EqualsRaw(TypeRefTable.GetNamespace(typeRef), s_projectionInfos[index].WinRTNamespace)) { isIDisposable = s_projectionInfos[index].IsIDisposable; return(index); } isIDisposable = false; return(-1); }
private bool HasAttribute(EntityHandle token, string asciiNamespaceName, string asciiTypeName) { foreach (var caHandle in GetCustomAttributes(token)) { StringHandle namespaceName, typeName; if (GetAttributeTypeNameRaw(caHandle, out namespaceName, out typeName) && StringStream.EqualsRaw(typeName, asciiTypeName) && StringStream.EqualsRaw(namespaceName, asciiNamespaceName)) { return(true); } } return(false); }
private TypeRefTreatment GetSpecialTypeRefTreatment(TypeReferenceHandle handle) { if (StringStream.EqualsRaw(TypeRefTable.GetNamespace(handle), "System")) { StringHandle name = TypeRefTable.GetName(handle); if (StringStream.EqualsRaw(name, "MulticastDelegate")) { return(TypeRefTreatment.SystemDelegate); } if (StringStream.EqualsRaw(name, "Attribute")) { return(TypeRefTreatment.SystemAttribute); } } return(TypeRefTreatment.None); }
/// <summary> /// The backing field of a WinRT enumeration type is not public although the backing fields /// of managed enumerations are. To allow managed languages to directly access this field, /// it is made public by the metadata adapter. /// </summary> private uint CalculateFieldDefTreatmentAndRowId(FieldDefinitionHandle handle) { var flags = FieldTable.GetFlags(handle); FieldDefTreatment treatment = FieldDefTreatment.None; if ((flags & FieldAttributes.RTSpecialName) != 0 && StringStream.EqualsRaw(FieldTable.GetName(handle), "value__")) { TypeDefinitionHandle typeDef = GetDeclaringType(handle); EntityHandle baseTypeHandle = TypeDefTable.GetExtends(typeDef); if (baseTypeHandle.Kind == HandleKind.TypeReference) { var typeRef = (TypeReferenceHandle)baseTypeHandle; if (StringStream.EqualsRaw(TypeRefTable.GetName(typeRef), "Enum") && StringStream.EqualsRaw(TypeRefTable.GetNamespace(typeRef), "System")) { treatment = FieldDefTreatment.EnumValue; } } } return(TreatmentAndRowId((byte)treatment, handle.RowId)); }
private bool IsSystemEnum(TypeReferenceHandle handle) { return(StringStream.EqualsRaw(TypeRefTable.GetNamespace(handle), "System") && StringStream.EqualsRaw(TypeRefTable.GetName(handle), "Enum")); }