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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:09:05+00:00 2026-05-27T08:09:05+00:00

I like to keep things separate when programming. That is one of the reasons

  • 0

I like to keep things separate when programming. That is one of the reasons why inheritance is important I believe.

I am using a dll file that consists of a class that I cannot modify. the dll file contains ClassA to illustrate my example.

class Program
{
    static void Main(string[] args)
    {
        ClassA object1 = new ClassA();

        SomeMethod<ClassA>(object1 ); // error because " a does not implement ITemp"
    }

    static T SomeMethod<T>(T input)
        where T:ITemp // make sure input has a method MyCustomMethod
    {

        input.MyCustomMethod();

        return input;
    }
     // create this interface so that compiler does not complain when
     // calling MyCustomMethod in method above

    interface ITemp
    {
        void MyCustomMethod();
    }

}


// classA is a sealed class in a dll file that I cannot modify
public class ClassA
{
    public void MyCustomMethod()
    {

    }
}

why is there an error if object1 does implement ITemp inteface! object1 has the method MyCustomMethod()

I know I can use reflection to solve this but I like to keep my code clean. also I want to avoid using the dynamic type.

  • 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-27T08:09:06+00:00Added an answer on May 27, 2026 at 8:09 am

    ClassA doesn’t implement the ITemp interface. Just because it has a method with the same name and signature as the method in the ITemp interface doesn’t mean it implements that interface. The class would need to be declared to implement it explicitly.

    Since you can’t extend ClassA, the best thing I can think of would be to wrap it with an adapter type class:

    public ClassB : ITemp {
        protected ClassA classAInstance;
    
        public ClassB( ClassA obj ) {
            classAInstance = obj;
        }
    
        public void MyCustomMethod() {
            classAInstance.MyCustomMethod();
        }
    }
    

    Then in your main method:

    static void Main(string[] args)
    {
        ClassA object1 = new ClassA();
    
        SomeMethod<ClassB>(new ClassB(object1));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to keep my concrete classes separate from my views. Without using strongly
I was recently told that I should keep my code in separate files; like
How do you like to organize your Drupal code? One giant module? Separate modules
To keep things organized I determined there are three item classes that a spider
Requirements I would like to keep an audit log of particular events, such as:
I would like to keep first link as default selected with javascript, here is
I would like to keep model binding when doing ajax calls from my view.
I'd like to keep my components/assemblies clearly separated from a source code point of
I'd like to keep my database clean of stale almost-accounts, and I was thinking
I'd like to keep some information on the client which element was clicked and

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.