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 we have two classes: class Base { private: int x; public: void f();
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have two classes deriving from a third abstract class: public abstract class
Suppose I have a class A which depends on 3 other classes X, Y
Suppose, I have following classes: public class DisposableObj : IDisposable { public ChildObj CreateObj();
Suppose you have 2 classes like so: public class ClassA { public int X
Suppose I have two classes defined the following way: public class A { public
Suppose I have two classes class A { b bInstance; public A ( b
Suppose i have a classes like this @Entity public class Customer implements Serializable {
Suppose I have two classes: public class Student { public int Id {get; set;}

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.