Skip to content

Instantly share code, notes, and snippets.

@GeorgeDellinger
Created March 10, 2014 13:01
Show Gist options
  • Save GeorgeDellinger/9464591 to your computer and use it in GitHub Desktop.
Save GeorgeDellinger/9464591 to your computer and use it in GitHub Desktop.
Return instance of Interface that has a method that returns true
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