Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6172803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:27:23+00:00 2026-05-23T23:27:23+00:00

I loved Loki’s C++ HierarchyGenerator and want to do the same in C#. What

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:27:26+00:00Added an answer on May 23, 2026 at 11:27 pm

    using t4:

    <#@ template debug="false" hostspecific="false" language="C#" #>
    <#@ output extension=".cs" #>
    
    <#@ import namespace="System.Text" #>
    <#@ import namespace="System.IO" #>
    <#@ import namespace="System" #>
    
    
    namespace SomeNamespace 
    {
    
        public interface Sender<T> 
        {
            void Send<T>(T t);
        };
        <# string[] strings={"Foo1","Foo2","Foo3"};
            foreach (String node in strings) 
            { #> partial class <#= node #> {}
            <# } #>
        class z {}
        public class FooSend: Sender<z><# 
             foreach (String node in strings) 
             { #>, Sender<<#= node #>> <# } #>
        {
        }
    }
    

    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:

    namespace SomeNamespace 
    {
    
        public interface Sender<T> 
        {
            void Send<T>(T t);
        };
         partial class Foo1 {}
         partial class Foo2 {}
         partial class Foo3 {}
         class z {}
        public class ParentClass : Sender<z>, Sender<Foo1> , Sender<Foo2> , Sender<Foo3>  {
        }    
    }
    

    Which fits my needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I love LINQ to SQL but it has been bugging me that in using
I always loved how i can quickly do with JavaScript: function hello(){ return ['foo',
I've always loved trees, that nice O(n*log(n)) and the tidiness of them. However, every
I've always loved trees, that nice O(n*log(n)) and the tidiness of them. However, every
just joined today loved this site already. My Question is that. i am trying
One of the things I loved about VB6 is that you had the ability
In Classic ASP, I loved the fact that I could write out variables, formulas,
nobody loved my first question about this: Creating Entity Framework objects with Unity for
I absolutely loved Dive Into Python when I picked up Python. In fact, tutorials
Back when I was learning HTML, I loved how easy it to build pages

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.