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

  • Home
  • SEARCH
  • 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 102143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:54:24+00:00 2026-05-11T00:54:24+00:00

I come from a C++ background where I can use template mixins to write

  • 0

I come from a C++ background where I can use template mixins to write code that refers to FinalClass which is a template parameter that is passed in. This allows reusable functions to be ‘mixed-in’ to any derived class, by simply inheriting from ReusableMixin with a template paramter of MyFinalClass. This all gets inlined into the class so it’s as though I just wrote a big class that did everything — ie very fast! Since mixins can chain, I can mix-in all sorts of behaviour (and state) into one object.

If anyone wants clarification on the technique, please ask. My question is, how can I get reuse like that in C#? Note: C# generics don’t allow inheriting from a generic parameter.

  • 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. 2026-05-11T00:54:25+00:00Added an answer on May 11, 2026 at 12:54 am

    In C#, the closest you get to C++ style mixins is adding the mixins as fields of a class and add a bunch of forwarding methods to the class:

    public class MyClass {     private readonly Mixin1 mixin1 = new Mixin1();     private readonly Mixin2 mixin2 = new Mixin2();      public int Property1     {         get { return this.mixin1.Property1; }         set { this.mixin1.Property1 = value; }     }      public void Do1()     {         this.mixin2.Do2();     } } 

    This is usually enough, if you only want to import functionality & state of the mixins. A mixin can of course be implemented as you like, complete with (private) fields, properties, methods, etc.

    If your class also needs to express ‘is-a’ relationships with the mixins then you need to do the following:

    interface IMixin1 {     int Property1 { get; set; } }  interface IMixin2 {     void Do2(); }  class MyClass : IMixin1, IMixin2 {     // implementation same as before } 

    (This is also the standard way how multiple inheritance is emulated in C#.)

    Of course, the mixin interfaces as well as the mixin classes can be generics, e.g. with a most-derived class parameter or whatever.

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

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You don't have to change it in the jquery-ui css… May 11, 2026 at 12:16 pm
  • added an answer No, you can not embed out-of-browser silverlight into WPF. The… May 11, 2026 at 12:16 pm
  • added an answer Law of Demeter. Create a property on MyClass that exposes… May 11, 2026 at 12:16 pm

Related Questions

I come from a C++ background where I can use template mixins to write
I come from a .NET world and I'm new to writting C++. I'm just
I come from a Java background, where packages are used, not namespaces. I'm used
I come from a mainly PHP background and make good use of the Apache
I come from a CVS background. I'm currently investigating using SVN for a project.
I come from a background of MoM. I think I understand ESB conceptually. However,
I come from a Java background and with any servlets-based technology, it's trivial to
I come from a java background. But I would like a cross-platform perspective on
I come from a PHP based background and my new years resolution was to
This is pretty simple, I come from a swing/awt background. I'm just wondering what

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.