Skip to content

Instantly share code, notes, and snippets.

@poulfoged
Created September 8, 2015 07:57
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 poulfoged/1927ce781ab624091871 to your computer and use it in GitHub Desktop.
Save poulfoged/1927ce781ab624091871 to your computer and use it in GitHub Desktop.
internal static class ReflectiveEnumerator
{
public static IEnumerable<Type> GetEnumerableOfType<T>() where T : class
{
var objects = Assembly
.GetAssembly(typeof (T))
.GetTypes()
.Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof (T)))
.ToList();
return objects;
}
public static IEnumerable<Type> GetEnumerableOfInterface<T>() where T : class
{
var objects = Assembly
.GetAssembly(typeof(T))
.GetTypes()
.Where(myType => myType.IsClass && !myType.IsAbstract && !myType.IsInterface && typeof(T).IsAssignableFrom(myType))
.ToList();
return objects;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment