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
   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. 


This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

Leave a Reply