Getting the instance that called the method in C#

后端 未结 5 1418
有刺的猬
有刺的猬 2021-02-18 16:05

I am looking for an algorithm that can get the object that called the method, within that method.

For instance:

public class Class1 {

    public void Me         


        
5条回答
  •  礼貌的吻别
    2021-02-18 16:45

    Obviously i don't know the exact details of your situation but this really seems like you need to rethink your structure a bit.

    This could easily be done if proper inheritance is structured.

    Consider looking into an abstract class and classes that inherit from said abstract class. You might even be able to accomplish the same thing with interfaces.

提交回复
热议问题