[英]Get reference of ParameterInfo parameter
我有方法
public void SomeMethod(string PersonName,int Age)
{
// get call stack
StackTrace stackTrace = new StackTrace();
// should equal "SomeMethod"
var MethodName = stackTrace.GetFrame(0).GetMethod().Name;
// should be ParameterInfo of parameter "PersonName"
var firstParam = stackTrace.GetFrame(0).GetMethod().GetParameters()[0];
// Here is where I get stuck !!!!!!!
var t = firstParam.GetValue();
我怎样才能获得firstParam参数指向的位置的引用以获得它的值?
我知道我可以通过PersonName得到它,但我想通过firstParam重新获取该信息。
反射信息不包含有关对象当前状态的数据,只包含参数信息的元数据。 即使您拥有PropertyInfo
类,也必须提供一个对象,使其具有该值的任何含义。 你最好只使用提供的参数值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.