Skip to content

Instantly share code, notes, and snippets.

@imwower
Created April 29, 2014 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imwower/11392782 to your computer and use it in GitHub Desktop.
Save imwower/11392782 to your computer and use it in GitHub Desktop.
reflect types to find implement from interface
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