public bool HasAttribute(MetadataReader reader, CustomAttributeHandleCollection attrHandles, string attributeFullName) { if (!_attributeConstructors.TryGetValue(attributeFullName, out var constructorSet)) { constructorSet = new HashSet <EntityHandle>(); _attributeConstructors[attributeFullName] = constructorSet; } var attrs = attrHandles.Select(reader.GetCustomAttribute).ToList(); if (attrs.Any(attr => constructorSet.Contains(attr.Constructor))) { return(true); } var compilerGeneratedAttr = attrs .Where(attr => reader.GetFullname(reader.GetCustomAttrClass(attr)) == attributeFullName) .Select(attr => (CustomAttribute?)attr) .FirstOrDefault(); if (compilerGeneratedAttr == null) { return(false); } constructorSet.Add(compilerGeneratedAttr.Value.Constructor); return(true); }
public static string ToString(this MetadataReader reader, CustomAttribute x) => $"{{CustomAttr[{RowId(x):X}]: {reader.ToString( reader.GetCustomAttrClass(x))} {reader.ToString( x.Parent)}}}";
public static EntityHandle GetCustomAttrClass(this MetadataReader reader, CustomAttributeHandle attrHandle) => reader.GetCustomAttrClass(reader.GetCustomAttribute(attrHandle));