11using System ;
2+ using System . Collections . Generic ;
23using System . Linq ;
34using System . Reflection ;
45
@@ -34,7 +35,33 @@ public static Type FindType(string typeFullName)
3435 . SelectMany ( assembly => assembly . GetTypes ( ) )
3536 . FirstOrDefault ( type => type . FullName == null || type . FullName . Equals ( typeFullName ) ) ;
3637 }
37-
38+
39+ /// <summary>
40+ /// Find all types that implement `T`.
41+ /// </summary>
42+ /// <typeparam name="T">Base type.</typeparam>
43+ /// <returns>Returns all types that are implement provided base type.</returns>
44+ public static IEnumerable < Type > FindImplementationsOf < T > ( )
45+ {
46+ var baseType = typeof ( T ) ;
47+ return FindImplementationsOf ( baseType ) ;
48+ }
49+
50+
51+ /// <summary>
52+ /// Find all types that implement `baseType`.
53+ /// </summary>
54+ /// <param name="baseType">Base type.</param>
55+ /// <returns>Returns all types that are implement provided base type.</returns>
56+ public static IEnumerable < Type > FindImplementationsOf ( Type baseType )
57+ {
58+ var implementations = AppDomain . CurrentDomain . GetAssemblies ( )
59+ . SelectMany ( assembly => assembly . GetTypes ( ) )
60+ . Where ( type => baseType . IsAssignableFrom ( type ) && ! type . IsInterface && ! type . IsAbstract ) ;
61+
62+ return implementations ;
63+ }
64+
3865 /// <summary>
3966 /// Get property value from an object by it's name.
4067 /// </summary>
@@ -46,7 +73,7 @@ public static object GetPropertyValue(object src, string propName, BindingFlags
4673 {
4774 return src . GetType ( ) . GetProperty ( propName , bindingAttr ) . GetValue ( src , null ) ;
4875 }
49-
76+
5077 /// <summary>
5178 /// Get property value from an object by it's name.
5279 /// </summary>
0 commit comments