Re: Destroying objects.
- From: "Brian Gideon" <briangideon@xxxxxxxxx>
- Date: 23 Feb 2006 18:15:01 -0800
I usually put all of my argument and state validation code at the top
of the methods in individual if statements. An ObjectDisposedException
should be thrown if that check fails. The problem with Assert is that
it won't make it into the release build.
I try to avoid throwing exceptions from properties since callers don't
expect them in that case.
CMM wrote:
You don't even have to do the conditional. You can put an Assert at the top
of the method property code which will terminate the method immediately if
m_disposed.
--
-C. Moya
www.cmoya.com
"CMM" <cmm@xxxxxxxxxx> wrote in message
news:eehL88MOGHA.3264@xxxxxxxxxxxxxxxxxxxxxxx
Not sure I understand. You can't control who "references" your object and
you can't control when the Garbage Collector destroys it (which it won't
do if there is anybody "referencing" it).
But, you sure can control whether your object kills itself (it refuses to
do work). Implement IDisposable. Call Dispose on the object... keep a
private variable stating in the object that states it considers itself
disposed and put in a conditional checks into each property and method
accessed in the object.
Public MyClass
Implements IDisposable
...
Public Sub DoSomething()
If Not m_disposed Then
'do your work
Else
Throw New Exception("nuh uh, you can't access me.")
End If
End Sub
Public Property Something
Get
If Not m_disposed Then
Return m_something
Else
Throw New Exception("nuh uh, you can't access me.")
End If
End Get
...
--
-C. Moya
www.cmoya.com
"qwert" <nospam@xxxxxxxxx> wrote in message
news:g5GdnQMyF-qNQmDeRVny1Q@xxxxxxxxxxxx
.
- Follow-Ups:
- Re: Destroying objects.
- From: CMM
- Re: Destroying objects.
- References:
- Destroying objects.
- From: qwert
- Re: Destroying objects.
- From: qwert
- Re: Destroying objects.
- From: Brian Gideon
- Re: Destroying objects.
- From: qwert
- Re: Destroying objects.
- From: CMM
- Re: Destroying objects.
- From: CMM
- Destroying objects.
- Prev by Date: Re: vb2005 propertybag
- Next by Date: After export to Excel, that excel cannot open
- Previous by thread: Re: Destroying objects.
- Next by thread: Re: Destroying objects.
- Index(es):