Finding the variable name passed to a function

前端 未结 17 2154
广开言路
广开言路 2020-11-22 04:11

Let me use the following example to explain my question:

public string ExampleFunction(string Variable) {
    return something;
}

string WhatIsMyName = "         


        
17条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 05:04

    The short answer is no ... unless you are really really motivated.

    The only way to do this would be via reflection and stack walking. You would have to get a stack frame, work out whereabouts in the calling function you where invoked from and then using the CodeDOM try to find the right part of the tree to see what the expression was.

    For example, what if the invocation was ExampleFunction("a" + "b")?

提交回复
热议问题