我有两个场景,我想知道我执行的某个方法的调用方方法是哪个。
以下是场景:
1)
public static void ExecuteMethod(object obj)
{
var mth = new StackTrace().GetFrame(1).GetMethod();
string methodName = mth.Name;
}
我这样称呼它:
public class Process
{
public int Handle { get; set; }
public string Name { get; set; }
public int ProcessID { get; set; }
public dynamic GetOwner()
{
return WMIMethod.ExecuteMethod(this);
}
}
当执行此操作时,
methodName
是我所期望的:
GetOwner
第二个有问题的场景是:
(二)
public static dynamic ExecuteMethod(object obj, dynamic parameters)
{
var mth = new StackTrace().GetFrame(1).GetMethod();
string methodName = mth.Name;
}
我这样称呼它:
public class Process
{
public int Handle { get; set; }
public string Name { get; set; }
public int ProcessID { get; set; }
public dynamic GetOwner(dynamic inParams)
{
return WMIMethod.ExecuteMethod(this, inParams);
}
}
在这种情况下,当我打电话
new Process().GetOwner(new { MyParam = "Something" } )
结果
调用的方法名
_不是我期望的那样了吗?(
获取所有者
)而不是那样
调用的方法名
是
CallSite.Target
结果是
mth
是
{Void CallSite.Target(System.Runtime.CompilerServices.Closure, System.Runtime.CompilerServices.CallSite, System.Type, ORMi.Sample.Models.Printer, System.Object)}
有人知道为什么第二种情况不同于第一种情况吗??。如何解决这个问题?是吗?.
谢谢!.