I would like to implement an current property in my class which returns the current active context of the class (much like httpcontext.current etc.), like so:
using(classA x = new classA(..))
{
classB.Dosomething();
}
where the method dosomething() gets the current context of classA to perform some operation.
How would i go about creating such functionality?
Greetz,
Richard
You should make a
[ThreadStatic] staticCurrent property, then writeCurrent = thisin the constructor, and set it tonullinDispose. You might want to throw an exception if someone makes a second copy in the same thread. Alternatively, you could maintain a stack.