Language: add ToEnum for Integer and Long

This commit is contained in:
Jonathan Jenne 2020-12-22 11:57:50 +01:00
parent 227ff3fcbb
commit 867cce7c13

View File

@ -22,6 +22,24 @@ Public Class Utils
Return [Enum].Parse(GetType(T), value)
End Function
''' <summary>
''' Converts an Integer value to the given Enum
''' </summary>
''' <typeparam name="T">The Enum Type</typeparam>
''' <param name="value">The integer value to convert</param>
Public Shared Function ToEnum(Of T)(value As Integer) As T
Return [Enum].ToObject(GetType(T), value)
End Function
''' <summary>
''' Converts a Long value to the given Enum
''' </summary>
''' <typeparam name="T">The Enum Type</typeparam>
''' <param name="value">The long value to convert</param>
Public Shared Function ToEnum(Of T)(value As Long) As T
Return [Enum].ToObject(GetType(T), value)
End Function
Public Shared Function ToBoolean(input As String) As Boolean
If String.IsNullOrEmpty(input) Then Return False
Return (input.Trim().ToLower() = "true") OrElse (input.Trim() = "1")