Option Explicit On Option Strict On ''' <summary> ''' This object is the object that all nullable objects should inherit from. ''' </summary> Public MustInherit Class NullableBaseObject Implements System.Data.SqlTypes.INullable #Region "Declarations" Protected _isNull As Boolean #End Region #Region "Properties" ''' <summary> ''' Gets a value indicating whether this instance has value. ''' </summary> ''' <value><c>true</c> if this instance has value; otherwise, false.</value> Public ReadOnly Property HasValue() As Boolean Get Return Not Me._isNull End Get End Property ''' <summary> ''' Gets a value indicating whether this instance is null. ''' </summary> ''' <value><c>true</c> if this instance is null; otherwise, false.</value> Public ReadOnly Property IsNull() As Boolean Implements System.Data.SqlTypes.INullable.IsNull Get Return Me._isNull End Get End Property #End Region #Region "Methods" ''' <summary> ''' Sets the internal is-null flag. ''' </summary> ''' <param name="value">if set to <c>true</c> [value]. Protected Sub SetIsNull(ByVal value As Boolean) Me._isNull = value End Sub #End Region End Class
Option Explicit On Option Strict On ''' <summary> ''' Represents nullable an instance in time, typically represented as a date and time. ''' </summary> <serializable()> _ Public Class DateTimeNull Inherits NullableBaseObject #Region "Declarations" Private _internalDate As System.DateTime #End Region #Region "Properties" ''' <summary> ''' Privately gets or sets the internal date. When set IsNull property is set to false. ''' </summary> ''' <value>The internal date.</value> Private Property InternalDate() As System.DateTime Get Return Me._internalDate End Get Set(ByVal value As System.DateTime) Me._internalDate = value If Me.IsNull Then Me.SetIsNull(False) End If End Set End Property #End Region End Class
#Region "Methods" ''' <summary> ''' Converts the value of this instance to its equivalent string representation. ''' </summary> ''' <returns> ''' A <see cref="System.String"> that represents this instance. ''' </returns> Public Overrides Function ToString() As String If Me.HasValue Then Return Me.InternalDate.ToString Else Return DBNull.Value.ToString End If End Function #End Region
#Region "Constructors" ''' <summary> ''' Initializes a new instance of the class, with IsNull = true. ''' </summary> Public Sub New() MyBase.New() Mybase.SetIsNull(True) End Sub #End Region
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.