I loved Loki's C++ HierarchyGenerator and want to do the same in C#.
What I want in the end is a class that has a virtual function per argument in a given typelist.
C++ code I'd like to convert:
template <class T>
class SenderV
{
public:
virtual void Send(T t) = 0;
};
template <int i>
class Foo // Just to make it easy to show typelist, it's not interesting.
{ /* doIt definition */ };
typedef TYPELIST_2(Foo<1>,Foo<2>) FooSendables;
template <typename TList=FooSendables>
class FooSend : public Loki::GenScatterHierarchy <TList,SenderV>
{
public:
void Send(Foo<1> f) {f.doIt();std::cout<<"Sending Foo1."<<std::endl;};
void Send(Foo<2> f) {f.doIt();std::cout<<"Sending Foo2."<<std::endl;};
};
in C#. If you aren't familiar with Loki, the FooSend class above would default to:
class FooSend : SenderV<Foo<1> >, SenderV<Foo<2> >//including every type in TList
{ /*... as above */};
But when a new TList is given, it'd be a different Hierarchy based on the Types in the TList.
I'm also interested in a GenLinearHierarchy in Loki if it exists out there.
I could always try to translate between the languages, but I'm not a big fan of trying that as I'm new to C# and just want to do my work, not learn the subtle difference between templates and generics.
using t4:
I can't get the formatting the way I'd like (and, regardless, the t4 formatting is always going to be ugly), but this solves my problem.
The code above produces:
Which fits my needs.