'''
''' Provides common utility functions that do not require a specific context.
'''
Public Class Utils
'''
''' Generates a random short (8 characters) guid
'''
''' The generated guid as a String
Public Shared Function ShortGUID() As String
Return Guid.NewGuid().ToString().GetHashCode().ToString("x")
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
'''
''' 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
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
End Class