I am looking for a C# solution that allows me to create a base class (AParam) whose inherited classes (Param) can be generic in order to implement different, type-dependent versions of a function (Serialize()). Ultimately, I want to be able to do something like in the code block below. I know that C# does not support template specialization. Is there a good workaround?
void Start()
{
List<AParam> tList = new List<AParam>();
tList.Add(new Param<int>());
tList.Add(new Param<bool>());
tList[0].Serialize();
}
In accordance with the specialization of Param, the respective implementation should be called directly on APram without manually executing type checks internally.
I have tried various interface and class combinations, but cannot get a working result.
Simon Spielmann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.