我在 C# 中有以下场景
public class classA
{
public int fieldA = 1;
public classA()
{
classB b=new classB();
b.Execute();
}
}
public class classB
{
public Execute()
{
//I can get the type of classA using
FieldInfo fi = stackTrace.GetFrame(1).GetMethod().DeclaringType
}
}
问题是如何获得在 classB 的实例中调用 Execute 的 classA 的引用?
我尝试使用反射,但找不到任何方法。
任何帮助将非常感激