Created
March 6, 2019 12:40
-
-
Save marijnz/7eacf646fd2dbdace7a0b3634dae9d16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Reflection; | |
namespace Assets.Scripts.Core | |
{ | |
public static class Utils | |
{ | |
public static IEnumerable<FieldInfo> GetFieldsWithAttribute<T>(this Type classType) | |
{ | |
var fields = classType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); | |
foreach (var field in fields) | |
{ | |
if(field.GetCustomAttributes(typeof(T), true).Length > 0) | |
{ | |
yield return field; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment