Skip to content

Instantly share code, notes, and snippets.

@marijnz
Created March 6, 2019 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marijnz/7eacf646fd2dbdace7a0b3634dae9d16 to your computer and use it in GitHub Desktop.
Save marijnz/7eacf646fd2dbdace7a0b3634dae9d16 to your computer and use it in GitHub Desktop.
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