Weaver Extensions: HasCustomAttribute uses Linq to simplify code

This commit is contained in:
vis2k 2020-08-21 11:38:32 +02:00
parent 467d9e834f
commit 2ea787f4fc

View File

@ -179,12 +179,8 @@ public static CustomAttribute GetCustomAttribute(this ICustomAttributeProvider m
public static bool HasCustomAttribute(this ICustomAttributeProvider attributeProvider, TypeReference attribute) public static bool HasCustomAttribute(this ICustomAttributeProvider attributeProvider, TypeReference attribute)
{ {
foreach (CustomAttribute ca in attributeProvider.CustomAttributes) // Linq allocations don't matter in weaver
{ return attributeProvider.CustomAttributes.Any(attr => attr.AttributeType.FullName == attribute.FullName);
if (ca.AttributeType.FullName == attribute.FullName)
return true;
}
return false;
} }
public static T GetField<T>(this CustomAttribute ca, string field, T defaultValue) public static T GetField<T>(this CustomAttribute ca, string field, T defaultValue)