one of those days ....

Posted Thu, Mar 13 2008 14:46 by bill

It must be hot or I'm having one of those days.  I was just testing some code and it seemed to do the unexpected.  The problem was I had written :

   Public Overrides ReadOnly Property IsInvalid() As Boolean

      Get

         Me.handle = IntPtr.Zero

      End Get

   End Property

This function was not only returning the wrong value but it was also changing the state !!

Okay, obviously I meant that to read:

         Return Me.handle = IntPtr.Zero

but I made a mistake. The problem was exasperated by no warning from VB that the Get wasn't returning a value.  I hate that. It's as bad as that stupid implicit local variable VB creates for you with the same name of the function.  I wish I could easily turn off VB's desire to help me as that would be in fact far more helpful ;)

And of course if there was an option to have a different equality operator from an assignment operator, that would have possibly helped a little in this case.  Maybe I should write it using the double negative:

        Return Not (Me.handle <> IntPtr.Zero)

;)

Filed under: ,