The general rule is that I want to say, "T has a method with a String parameter which will return List." Put verbosely, we might call the interface ICanCreateListOfObjectsFromString. A possible application might be search.
It feels like it'd be nice to have a static method in my interface, but I know that's not allowed in C#. What is another approach to specify this kind of contract implementation on a class?
Edit: I would like to have the following code:
public interface ISearch
{
static List<T> Search<T>(String s);
}
public class MyObject : ISearch {
List<MyObject> Search(string s) {
//...
}
}
public List<T> DoFooSearch<T:ISearch> () {
return T.Search("Foo");
}
public List<T> DoBarSearch<T:ISearch> () {
return T.Search("Bar");
}
You can probably see why this code won't compile, but it expresses the spirit of what I'd like to achieve. I hope this clarifies my intention a bit.