我有一个函数调用另一个函数。我想知道如果在第二个函数内,我可以检测它是否从使用范围内的第一个函数调用。如果我能检测到它,我想访问该使用范围内的变量。我无法通过参数发送变量。是否可以从另一个函数中检测使用的变量并访问该变量?
例如:
// Normal call to OtherFunction
void function1()
{
SomeClass.OtherFunction();
}
// Calling using someVar
void function2()
{
using(var someVar = new someVar())
{
SomeClass.OtherFunction();
}
}
// Calling using other variable, in this case, similar behaviour to function1()
void function3()
{
using(var anotherVar = new anotherVar())
{
SomeClass.OtherFunction();
}
}
class SomeClass
{
static void OtherFunction()
{
// how to know if i am being called inside a using(someVar)
// and access local variables from someVar
}
}
为什么你不能将它们作为参数发送? – PoweredByOrange 2013-05-10 16:11:05
'someVar'和'anotherVar'是否允许有相同的基类? – 2013-05-10 16:15:53
@ programmer93,因为在一个用于大量项目的程序集中,我无法重建所有这些程序。 – NioZero 2013-05-10 16:56:07