using MonoFN.Cecil; using System.Linq; namespace FishNet.CodeGenerating.Helping.Extension { internal static class CustomAttributeExtensions { /// /// Finds a field within an attribute. /// /// /// /// /// /// internal static T GetField(this CustomAttribute customAttr, string field, T defaultValue) { foreach (CustomAttributeNamedArgument customField in customAttr.Fields) { if (customField.Name == field) { return (T)customField.Argument.Value; } } return defaultValue; } /// /// Returns if any of the attributes match IAtrribute. /// /// /// /// internal static bool HasCustomAttribute(this ICustomAttributeProvider attributeProvider) { return attributeProvider.CustomAttributes.Any(attr => attr.AttributeType.Is()); } /// /// Returns if ca is of type target. /// /// /// /// internal static bool Is(this CustomAttribute ca, string targetFullName) { return ca.AttributeType.FullName == targetFullName; } } }