Created
March 22, 2018 12:08
-
-
Save johnw86/8e02b855c5d31069835c052ab56367fc to your computer and use it in GitHub Desktop.
Use Reflection to create instance of all implementations of an interface.
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
var implementations = Assembly.GetExecutingAssembly().GetTypes() | |
.Where(x => typeof(IInterface).IsAssignableFrom(x) && | |
!x.IsInterface && | |
!x.IsAbstract && | |
x.IsClass && | |
x.IsPublic) | |
.Select(x => Activator.CreateInstance(x) as IInterface); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment