Last active
August 29, 2015 14:02
-
-
Save omni-/f531d9f2759bf035b687 to your computer and use it in GitHub Desktop.
Get all derived classes
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
public static IEnumerable<T> GetEnumerableOfType<T>(params object[] constructorArgs) | |
{ | |
return Assembly.GetAssembly(typeof (T)).GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof (T))).Select(type => (T) Activator.CreateInstance(type, constructorArgs)).ToList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function can be used to get all derived classes of a parent type
usage:
output: