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 905601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:14:52+00:00 2026-05-15T16:14:52+00:00

I do understand that there’s no multiple inheritence in C#. However, I’ve run into

  • 0

I do understand that there’s no multiple inheritence in C#. However, I’ve run into a situation in which I really wish it existed. I am creating a custom class that requires me to inherit from CLR types and override a few methods. Unfortunately, I am creating several of these which are very similar. In the interest of DRY, I’d really want to move common functionality to a base class, but then I’d need to inherit from 2 classes. I can use interfaces (and infact I am using one right now) but this solves only half the problem as the method implementations still need to be repeated across several custom classes.

What’s the purist way of achieving what I am trying to do?

EDIT:

Here’s a generic code sample

public class CustomTypeOne : CLRType
{
   public override void Execute(HttpContext context)
   {
        //Some code that's similar across CustomTypeOne, CustomTypeTwo etc
   }

   public void DoStuff()
   {
       //Same for all CustomTypes and can be part of a base class
   }

   //More methods
}

public class CustomTypeTwo : CLRType
{
   public override void Execute(HttpContext context)
   {
        //Some code that's similar across CustomTypeOne, CustomTypeTwo etc
   }

   public void DoStuff()
   {
       //Same for all CustomTypes and can be part of a base class
   }

   //More methods

}
  • 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-15T16:14:53+00:00Added an answer on May 15, 2026 at 4:14 pm

    There are a few ways to implement what you are talking about.

    Assuming that you have a structure like like

    MyTypeA : CLR_TypeA
    {
        public override ToString()
        {
           //do some complicated stuff
        }
    }
    MyTypeB : CLR_TypeB
    {
        public override ToString()
        {
           //do the same complicated stuff
        }
    }
    

    Then it makes sense to want to have a base class, but you can’t. One method that other answers mentioned is composition. However in your case it might be possible to create another static class

    public static class ToStringHelpers
    {
        public static DoComplicatedStuff()
        {
           //do some pretty wild stuff.
        }
    }
    
    MyTypeA : CLR_TypeA
    {
        public override ToString()
        {
           DoComplicatedStuff();
        }
    }
    MyTypeB : CLR_TypeB
    {
        public override ToString()
        {
           DoComplicatedStuff();
        }
    }
    

    Then you have all of your disparate objects that need duplicate functionality call the helper method. The only advantage multiple inheritance would have in this case is that you wouldn’t have to write “DoComplicatedStuff()” over and over, but copy/paste will clean up that problem pretty quick anyway.

    EDIT

    If you are inheriting from the same type, then you don’t need MI for this

    MyBaseType : CLRType
    {
       public override void Execute(HttpContext context)
       {
           //Some code that's similar across CustomTypeOne, CustomTypeTwo etc
       }
    
       public void DoStuff()
       {
          //Same for all CustomTypes and can be part of a base class
       }
    
    }
    
    MyTypeA : MyBaseType
    {
        public void MyTypeACustomMethod()
        { 
          //do class specific logic here
        }
    }
    
    MyTypeB : MyBaseType
    {
        public void MyTypeBCustomMethod()
        { 
          //do class specific logic here
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to debug CoffeeScript line-by-line? I understand that it compiles into
There is something that I really don't understand with the HttpListener. The code below
I understand that there is a *.className selector since there can be multiple html
I understand that there are @Before and @BeforeClass , which are used to define
I understand that there is no way to kill the iframe breaker... However, I
I understand that 64-bit is the best. However, I've heard that there may be
I understand that there is a method invocation style subprogram call in Ada, however,
I understand that there's an nginx configuration file at http://www.friendfeed.com But i don't really
I understand that there is a setting in Sun JVM for dumping the heap
Are there overall rules/guidelines for what makes a method thread-safe? I understand that there

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.