0

Forgive me for the absolutely abominable title of my question, but what I mean is: There is an object A that has a method mA that executes a method mB from an object B, then that method (mB) executes mC from the same object, finally, mC executes a virtual method mD from an object C, which I have overridden.

In code:

class A
{
    B b;
    void mA()
    {
        b.mB();
    }
}

class B
{
    public void mB()
    {
        mC();
    }

    D d;

    void mC()
    {
        d.mD();
    } 
}


class C
{
    public virtual void mD() { }
}

class D : C
{
    public override void mD()
    {
        A a = // Somehow get the A object that executed this
    }
}

Now that you know the very confusing situation, could you tell me how I would get object A from mD? (I do mean object, not class)

Before anyone tries to murder for crimes against good code, I just want to clarify that I'm making a mod, and cannot edit any of the classes (other than D). So this has to be solved some other way, I'm guessing through some reflection shenanigans, which I am okay with.

Thank you in advance.

Parasol Kirby
  • 351
  • 1
  • 11
  • 2
    The only thing you can do is get the current stack trace, but that isn't very efficient. But you win a prize for best title of the day! – DavidG Aug 12 '22 at 12:33
  • [StackTrace Class](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.stacktrace?view=net-6.0) – Jonathan Dodds Aug 12 '22 at 12:40

0 Answers0