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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:23:50+00:00 2026-05-31T16:23:50+00:00

First look at this code: class Program { static void Main(string[] args) { var

  • 0

First look at this code:

class Program
{
  static void Main(string[] args)
  {
    var x =(Base) new Derived();
    ((IMethod)x).DoWork();

    Console.ReadKey();
  }
}

interface IMethod
{
  void DoWork();
}

abstract class Base : IMethod
{
  void IMethod.DoWork()
  {
    Console.WriteLine("Base.DoWork");
  }
}

class Derived : Base, IMethod
{
  public void DoWork()
  {
    //here I where I want to call base.DoWork();
    Console.WriteLine("Derived.DoWork"); 
  }
}

Output:

Derived.DoWork

Desired:

Base.DoWork
Derived.DoWork

I’m dealing with an API that exposes an interface that when implemented, the DoWork method will be called at some part of the procession.

Now in the above example, the class Base is a part of the API, that internally (in the API) already explicitly implements that interface and does some important executions in the DoWork method.

I need to override the implementation of the IMethod in my derived class as well, so I get notified when needed, the problem is I can’t ‘override’ the method and call the base method, neither can I cast base to IMethod.

Any solution?

Note: reflection won’t work since it’s a Silveright project, and private method invoking is prohibited.

  • 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-31T16:23:51+00:00Added an answer on May 31, 2026 at 4:23 pm

    I’ve found DanBryant’s comment to be the answer, although as he mentions is a bit risky since we can’t assure the implementer will call the base method, but is a decent way tho.

    I made a protected virtual method that is called from the private interface implementer, then, in the derived class, instead of worrying about the interface, I just care about overriding the base class and calling the base implementation from it, that works perfect, example:

    abstract class Base : IMethod
    {
      void IMethod.DoWork()
      {
        DoWork();
      }
    
      protected virtual void DoWork()
      {
        Console.WriteLine("Base.DoWork");
      }
    }
    
    class Derived : Base
    {
      protected override void DoWork()
      {
        base.DoWork();
        //here I where I want to call base.DoWork();
        Console.WriteLine("Derived.DoWork");
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

at first i'm really new to ORM, nhibernate and FHN. i look into this
First of all have a look at the following code (in this code shape
First look at this url: https://stackoverflow.com/questions/tagged/xoxoxo/ This directory does not exists but somehow stackoverflow
I have tried this example http://www.bennadel.com/blog/1056-ColdFusion-CFPOP-My-First-Look.htm , but it retrieve emails from POP server.
First of all I did gave a look at this one. But I didn't
Take a look at this screenshoot first: That white box is ON the orange
Please take a look at this screenshot first: I would like to move the
First of all my tree is made up of nodes that look like this:
First of all thanks for taking the time to look into this. I store
This is one of my first issues. Whenever I exit out the program, tcpClient.Connect()

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.