Overloading SmartDate constructor to take an enum instead of boolean

Overloading SmartDate constructor to take an enum instead of boolean

Old forum URL: forums.lhotka.net/forums/t/540.aspx


KerryJenkins posted on Tuesday, July 04, 2006

Can you think of any problems that overloading the SmartDate constructor to take an enum would cause.  Example:

Public Enum EmptyDefault
   Min
   Max
End Enum

Public Sub New(ByVal emptyDefaultValue As EmptyDefault)
   Me
.New(emptyDefaultValue = EmptyDefault.Min)
End Sub

Public Sub New(ByVal value As Date, ByVal emptyDefaultValue As EmptyDefault)
   Me
.New(value, (emptyDefaultValue = EmptyDefault.Min))
End Sub

Public Sub New(ByVal value As String, _
              
ByVal emptyDefaultValue As EmptyDefault)
   Me
.New(value, (emptyDefaultValue = EmptyDefault.Min))
End
Sub

This would allow client code to explicitly specify what the empty default should be in a way that would be apparent to anyone looking at the code.

Example:
Private mEnded as New SmartDate(SmartDate.EmptyDefault.Max)

Thanks,
Kerry

RockfordLhotka replied on Friday, July 07, 2006

This does seem like a good idea - makes the code more readable certainly - thanks!

Copyright (c) Marimer LLC