Add RegexEditor, Improve Database Add Language
This commit is contained in:
38
Modules.Language/Utils.vb
Normal file
38
Modules.Language/Utils.vb
Normal file
@@ -0,0 +1,38 @@
|
||||
''' <summary>
|
||||
''' Provides common utility functions that do not require a specific context.
|
||||
''' </summary>
|
||||
Public Class Utils
|
||||
''' <summary>
|
||||
''' Generates a random short (8 characters) guid
|
||||
''' </summary>
|
||||
''' <returns>The generated guid as a String</returns>
|
||||
Public Shared Function ShortGUID() As String
|
||||
Return Guid.NewGuid().ToString().GetHashCode().ToString("x")
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Converts a String value to the given Enum
|
||||
''' </summary>
|
||||
''' <typeparam name="T">The Enum Type</typeparam>
|
||||
''' <param name="value">The string value to convert</param>
|
||||
Public Shared Function ToEnum(Of T)(value As String) As T
|
||||
Return [Enum].Parse(GetType(T), value)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Checks a value for three different `null` values,
|
||||
''' Nothing, Empty String, DBNull
|
||||
'''
|
||||
''' Returns the original value if the value is not null, or `defaultValue`
|
||||
''' </summary>
|
||||
''' <typeparam name="T">The type of the value</typeparam>
|
||||
''' <param name="value">The value</param>
|
||||
''' <param name="defaultValue">The default Value</param>
|
||||
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
|
||||
Reference in New Issue
Block a user