Public Class ObjectEx
'''
''' Checks a value for three different `null` values,
''' Nothing, Empty String, DBNull
'''
''' Returns the original value if the value is not null, or `defaultValue`
'''
''' The type of the value
''' The value
''' The default Value
''' The original value or the default value
Public Shared Function NotNull(Of T)(ByVal value As T, ByVal defaultValue As T) As T
If IsNothing(value) OrElse String.IsNullOrEmpty(value.ToString) OrElse IsDBNull(value) Then
Return defaultValue
Else
Return value
End If
End Function
'''
''' Converts a String value to the given Enum
'''
''' The Enum Type
''' The string value to convert
Public Shared Function ToEnum(Of T)(value As String) As T
Return [Enum].Parse(GetType(T), value)
End Function
'''
''' Converts an Integer value to the given Enum
'''
''' The Enum Type
''' The integer value to convert
Public Shared Function ToEnum(Of T)(value As Integer) As T
Return [Enum].ToObject(GetType(T), value)
End Function
'''
''' Converts a Long value to the given Enum
'''
''' The Enum Type
''' The long value to convert
Public Shared Function ToEnum(Of T)(value As Long) As T
Return [Enum].ToObject(GetType(T), value)
End Function
End Class