Language: Add NotNull function for DataRows

This commit is contained in:
Jonathan Jenne 2021-05-20 16:07:22 +02:00
parent 667dd65436
commit 0c4e1879aa

View File

@ -54,6 +54,7 @@ Public Class Utils
''' <typeparam name="T">The type of the value</typeparam>
''' <param name="value">The value</param>
''' <param name="defaultValue">The default Value</param>
''' <returns>The original value or the default value</returns>
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
@ -62,6 +63,21 @@ Public Class Utils
End If
End Function
''' <summary>
''' Checks a Row 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="Row">The DataRow that contains the value</param>
''' <param name="Column">The column name</param>
''' <param name="DefaultValue">The default value</param>
''' <returns>The original value or the default value</returns>
Public Shared Function NotNull(Of T)(ByVal Row As DataRow, Column As String, DefaultValue As T) As T
Return NotNull(Row.Item(Column), DefaultValue)
End Function
''' <summary>
''' Creates a "slug" from text that can be used as part of a valid URL.
''' Invalid characters are converted to hyphens. Punctuation that Is