I have a hierarchy of ISomething
objects, and now I am trying to get a separate objects to calculate parameters for the ISomething
objects. I expect a pretty much one-to-one mapping.
public interface ISomething
{
void SetParameters(IParameters p);
}
public interface IParameterCalculator<TSomething> where TSomething : class, ISomething
{
IParameters Calculate();
}
I would like to make it a bit more type safe, e.g. to make sure that the parameters calculated by a given calculator will fit only to the related something object. So I tried making parameters generic:
public interface IParameterCalculator<TSomething> where TSomething : class, ISomething
{
IParameters<TSomething> Calculate();
}
I am not sure though how to consume this in the ISomething interface. In C++
there are standard hacks with the templates to achieve this, are there similar techniques in C#
? Or any other ideas how to link the IParameterCalculator
hierarchy to ISomething
in a type-safe way?