Created
March 10, 2014 13:01
-
-
Save GeorgeDellinger/9464591 to your computer and use it in GitHub Desktop.
Return instance of Interface that has a method that returns true
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
public static ISomeInterface GetInstance(string record) | |
{ | |
var instances = from t in Assembly.GetExecutingAssembly().GetTypes() | |
where t.GetInterfaces().Contains(typeof(ISomeInterface)) | |
&& t.GetConstructor(Type.EmptyTypes) != null | |
orderby t.Name | |
select Activator.CreateInstance(t) as ISomeInterface; | |
return (from instance in instances | |
where instance.IsMatch(record) | |
select instance).FirstOrDefault(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment