' This class is responsible for any miscellaneous functions that don't fit into any OO definition. Typically data type conversions, ' manipulations, validation etc... Public Class Utils Private Const CLASS_NAME As String = "Utils" '################################################################################################################################# ' Checks the string for a valid string object. ' Param: String value. The string to validate ' Return: Boolean. True if the value is nothing/null, empty, or zero length("") Public Shared Function IsNull(ByVal value As String) As Boolean Const METHOD_NAME As String = "IsNull" Try Return (value Is Nothing OrElsevalue.Trim().Length().Equals(0)) Catch ex As Exception Log.WriteLogEntry(ex, CLASS_NAME, METHOD_NAME) End Try End Function '################################################################################################################################# ' Checks the DateTime object for a valid date ' Param: DateTime value. The date to validate ' Return: Boolean. True if the value is #12:00:00AM 0001" Public Shared Function IsNull(ByVal value As DateTime) As Boolean Const METHOD_NAME As String = "IsNull" Try Return (value.Year = 1) Catch ex As Exception Log.WriteLogEntry(ex, CLASS_NAME, METHOD_NAME) End Try End Function '################################################################################################################################# ' Checks the object for a valid value Public Shared Function IsNull(ByVal value As System.Object) As Boolean Const METHOD_NAME As String = "IsNull" Try Return (value Is Nothing OrElsevalue.ToString().Length.Equals(0)) Catch ex As Exception Log.WriteLogEntry(ex, CLASS_NAME, METHOD_NAME) End Try End Function '################################################################################################################################# ' Checks the string for a valid string object, and if no valid string is present, an exception is thrown '################################################################################################################################# Public Shared Sub Assert(ByVal value As String) If IsNull(value) Then Throw New Exception("Parameter not initialized") End Sub Public Shared Sub Assert(ByVal value As Object) If value Is Nothing Then Throw New Exception("Object was null") End Sub Public Shared Sub Assert(ByVal value As Int32) If IsValidPk(value) = False Then Throw New Exception("Invalid integer") End Sub Public Shared Function IsValidPk(ByVal value As Int32) As Boolean Return (value > 0) End Function Public Shared Function IsValidDate(ByVal value As Object) As Boolean Try Dim NewValue As DateTime = System.Convert.ToDateTime(value) Return NewValue.Year <> 1 Catch ex As Exception Return False End Try End Function ' Converts any member of the ICollection interface into a comma separate string of values Public Shared Function ConvertCollectionToCSV(ByVal Col As ICollection) As String Dim value As Object Dim Result As String Dim First As Boolean = True For Each value In Col If First Then Result = value.ToString() First = False Else Result += "," + value.ToString() End If Next Return Result End Function End Class |