What is the best way to check if a field has a particular custom attribute?
My current approach is like so, but it seems a little redundant:
foreach (FieldInfo fi in typeof(ClassName).GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
{
if (fi.GetCustomAttribute<AttributeName>() is AttributeName)
{
Debug.Log($"my GetCustomAttribute check was true for {fi.Name}.");
}
}
Aucun commentaire:
Enregistrer un commentaire