I have a class, has a start(), end() method.
I want to make sure that start() and end() should be
always paired called in the same codeblock or function,
i.e.:
try
{
o.Start();
...
}
Finally
{
o.End();
}
I could write the documentation, but is there anyway to
enforce this rule by compiler or runtime so it will
generate Compiling Error or Runtime Error if they are not
called in Pair?
-----Miss the Destructor in C++
Calvin
Calvin,
Unfortunately no. The closest you will get is to have end, renamed Dispose
from the IDisposable interface, then recommend to your clients that they use
the 'using' statement in their code, which will automatically call the
Dispose method.
using (Calvin o = new Calvin())
{
...
}
You could set some flag in your start method, that get reset in your end
method, that subsequently in the Finalize method it gets flagged, however
this would be way too late...
Hope this helps
Jay
> I have a class, has a start(), end() method.
>
[quoted text clipped - 19 lines]
>
> Calvin
Calvin - 14 Jul 2003 22:26 GMT
Thanks for the reply.
I am just not sure where the technology is going. The
destructor in C++ is so handy, and they just take it away.
And gone all the goods of C++ compiler. :-)
The attributes is great if they are truly extensible. Will
it be great if we can specify some local variable as:
[RunDestructor]
MyClass myobj = new MyClass();
?? :-)
.Net use Garbage Collector to take care memory problem,
but for some coputer resources, it's so important to
release immediately, or else it will crush the
application. And we really should not depend on the
programmers to call:
obj.Close();
manually.
Calvin
>-----Original Message-----
>Calvin,
[quoted text clipped - 40 lines]
>
>.