Last active
December 18, 2015 16:39
-
-
Save sebnilsson/5812989 to your computer and use it in GitHub Desktop.
Helper to get types assignable from specific type, with reflection.
This file contains 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<Type> GetAssemblyTypes<TType>(params Assembly[] assemblies) | |
{ | |
return GetAssemblyTypes(typeof(TType), assemblies); | |
} | |
public static IEnumerable<Type> GetAssemblyTypes(Type rootType, params Assembly[] assemblies) | |
{ | |
if (assemblies == null || !assemblies.Any()) | |
{ | |
assemblies = new[] { rootType.Assembly }; | |
} | |
return assemblies.SelectMany(assembly => assembly.GetTypes().Where(rootType.IsAssignableFrom)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment