簡體   English   中英

獲取ParameterInfo參數的參考

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM