Created
April 29, 2014 07:18
-
-
Save imwower/11392782 to your computer and use it in GitHub Desktop.
reflect types to find implement from interface
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
namespace ConsoleApplication2 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory+ "ConsoleApplication2.exe"); | |
var types = assembly.GetTypes(); | |
var interfaces = types.Where(t => t.IsInterface); | |
var implemetions = types.Where(t => !t.IsInterface && !t.IsAbstract); | |
var filters = | |
from @interface in interfaces | |
from implemetion in implemetions | |
where @interface.IsAssignableFrom(implemetion) | |
select new | |
{ | |
Interface = @interface, | |
Implemention = implemetion | |
}; | |
foreach (var item in filters) | |
{ | |
} | |
} | |
} | |
public interface IClass | |
{ | |
void Hello(); | |
} | |
public class Class1 : IClass | |
{ | |
public void Hello() | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment