CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Grant Killian's Blog

No, this has nothing to do with beer -- but maybe it should?

Option Strict On Salvation

Yeah, I should have put this in my earlier post but I didn't have time.  Maybe I'm crazy, but the whole Option Strict stuff with the TimeTracker starter kit is something I lose sleep over.  The solution is easy: just add a few ToString() and DateTime.Parse() functions where necessary . . . and then you have the whole ubiquitous IIF() function to wrestle with.   There's dozens of calls to the Option-Strict-On-hating Visual Basic IIF() function scattered all through the starter kit so fight that initial urge to do a search and replace approach.  And no, VB.Net doesn't have a ? operator either. 

Instead, overload IIF() with the appropriate strongly typed parameters and you'll be all set.  This is an example:

Public Class IIFHelper
 Public Shared Function IIF( Condition as Boolean, TrueResult as String, FalseResult as String ) as String
  If Condition Then
   return TrueResult
  Else
   return FalseResult
  End If
 End Function
End Class

Repeat as necessary and start using IIFHelper.IIF() instead of just IIF() -- I found only a handful of IIFHelper.IIF permutations necessary to get to Option Strict On salvation.

Now I can rest easier. 

 



Check out Devlicio.us!