How do I set properties related to the calling method's scope?

Posted by Thiado de Arruda on Stack Overflow See other posts from Stack Overflow or by Thiado de Arruda
Published on 2010-05-11T15:19:57Z Indexed on 2010/05/11 15:24 UTC
Read the original article Hit count: 183

Filed under:
|
|
|

I'm not looking for a way to associate values with a thread using the 'SetData' method.

I need to store some kind of data that will only exist during the scope of a calling method, could be the immediate parent or any other call that is made down on the stack. For example:

void SomeMethod()
{
   string someInfo = "someInfo";
   SomeOtherMethod();   
   object data = GetDataOnCurrentScope("someKey");
}

void SomeOtherMethod()
{
   SetDataOnParentScope("someKey", somevalue);
}

In this case both the 'someInfo' local variable and the data set with the "someKey" key will disapear after 'SomeMethod' returns. Is something like this possible? This may go against the rules of a stack, but who knows if someone has an idea...

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET