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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:43:16+00:00 2026-05-15T00:43:16+00:00

Suppose we have 2 classes, Child, and the class from which it inherits, Parent.

  • 0

Suppose we have 2 classes, Child, and the class from which it inherits, Parent.

class Parent
{
    public static void MyFunction(){}
}

class Child : Parent
{
}

Is it possible to determine in the parent class how the method was called? Because we can call it two ways:

Parent.MyFunction();
Child.MyFunction();

My current approach was trying to use:

MethodInfo.GetCurrentMethod().ReflectedType; // and
MethodInfo.GetCurrentMethod().DeclaringType;

But both appear to return the Parent type.

If you are wondering what, exactly I am trying to accomplish (and why I am violating the basic OOP rule that the parent shouldn’t have to know anything about the child), the short of it is this (let me know if you want the long version):

I have a Model structure representing some of our data that persists to the database. All of these models inherit from an abstract Parent. This parent implements a couple of events, such as SaveEvent, DeleteEvent, etc. We want to be able to subscribe to events specific to the type. So, even though the event is in the parent, I want to be able to do:

Child.SaveEvent += new EventHandler((sender, args) => {});

I have everything in place, where the event is actually backed by a dictionary of event handlers, hashed by type. The last thing I need to get working is correctly detecting the Child type, when doing Child.SaveEvent.

I know I can implement the event in each child class (even forcing it through use of abstract), but it would be nice to keep it all in the parent, which is the class actually firing the events (since it implements the common save/delete/change functionality).

  • 1 1 Answer
  • 2 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-15T00:43:17+00:00Added an answer on May 15, 2026 at 12:43 am

    No – calling Child.MyFunction() results in IL which calls Parent.MyFunction() directly. The resulting binary is basically indistinguishable.

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

Sidebar

Related Questions

Suppose you have a collection of Foo classes: class Foo { public string Bar;
Say I have the following code: class Parent { static string MyField = ParentField;
Suppose I have three classes. It is valid to instantiate A, but there are
Suppose I have two classes with the same interface: interface ISomeInterface { int foo{get;
Suppose I have a class module clsMyClass with an object as a member variable.
Suppose I have BaseClass with public methods A and B, and I create DerivedClass
Suppose you have a base class A, and this class is reimplemented by B
I have a class ImageA, and a class ImageB. The both classes represents an
Suppose you have 2 different ASP.NET applications in IIS. Also, you have some ASCX
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new

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.