44 lines
1.4 KiB
VB.net
44 lines
1.4 KiB
VB.net
Imports System.Runtime.CompilerServices
|
|
|
|
Public Module DataTableEx
|
|
<Extension()>
|
|
Public Function ItemEx(Of T)(pRow As DataRow, pFieldName As String, Optional pDefaultValue As T = Nothing) As T
|
|
Try
|
|
Return Utils.NotNull(pRow.Item(pFieldName), pDefaultValue)
|
|
Catch ex As Exception
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
|
|
<Extension()>
|
|
Public Function ItemEx(Of T)(pRow As DataRow, pFieldIndex As Integer, Optional pDefaultValue As T = Nothing) As T
|
|
Try
|
|
Return Utils.NotNull(pRow.Item(pFieldIndex), pDefaultValue)
|
|
Catch ex As Exception
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
|
|
<Extension()>
|
|
Public Function FieldOrDefault(Of T)(pRow As DataRow, pFieldName As String, Optional pDefaultValue As T = Nothing) As T
|
|
Return ItemEx(pRow, pFieldName, pDefaultValue)
|
|
End Function
|
|
|
|
<Extension()>
|
|
Public Function FieldOrDefault(Of T)(pRow As DataRow, pFieldIndex As Integer, Optional pDefaultValue As T = Nothing) As T
|
|
Return ItemEx(pRow, pFieldIndex, pDefaultValue)
|
|
End Function
|
|
|
|
<Extension()>
|
|
Public Function First(pTable As DataTable) As DataRow
|
|
Try
|
|
If pTable Is Nothing OrElse pTable.Rows.Count = 0 Then
|
|
Return Nothing
|
|
End If
|
|
Return pTable.Rows.Item(0)
|
|
Catch ex As Exception
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
End Module
|