out of scope

J

JT

Hi,

I like to output log to help with debugging. When there's a lot of recursive
functions, I like to increase the indentation of each line so I know where I
am "in the recursiveness". To do that indentation (when I program in c++), I
use a class that increases the indentation in the consturctor, and decreases
it in the destructor. When an instance of that class goes out of scope, the
indentation is automatically decreased. It works great.

Anyway, is there a way to do that in C#? I quickly ported my C++ code, but
quickly noticed that the destructor wasn't getting called. So the
indentation kept increasing, never decreasing. Is there any way to have a
member function called as soon as a variable goes out of scope in c#?

Thanks
JT
 
F

Frank Oquendo

JT said:
Anyway, is there a way to do that in C#? I quickly ported my C++
code, but quickly noticed that the destructor wasn't getting called.
So the indentation kept increasing, never decreasing. Is there any
way to have a member function called as soon as a variable goes out
of scope in c#?

C# does not support finalistic determination. Implement IDisposable and have
the Dispose method call the code to decrease the indent.

BTW, the Trace and Debug classes have simple indentation properties. You
might want to check them out.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top