Looking at this question I started thinking about how to handle constructor requirements in C#.
Assume that I have:
T SomeMethod<T>(string s) : where T : MyInterface
{
return new T(s);
}
I want to set the requirement on T that it can be constructed out of a string, but as far as I know, constructor definitions are not allowed as part of interfaces. Is there a standard way to solve this?
Add an init method or a property to your interface,
As you can’t specify arguments to constructor constraints