I have 3 similar functions, that only change based on numeric type:
<Extension()> _
Public Function ToNullableShort(ByVal str As String) As Short?
Dim intReturn As Short
If Short.TryParse(str, intReturn) Then
Return intReturn
Else
Return Nothing
End If
End Function
<Extension()> _
Public Function ToNullableByte(ByVal str As String) As Byte?
Dim intReturn As Byte
If Byte.TryParse(str, intReturn) Then
Return intReturn
Else
Return Nothing
End If
End Function
<Extension()> _
Public Function ToNullableLong(ByVal str As String) As Long?
Dim intReturn As Long
If Long.TryParse(str, intReturn) Then
Return intReturn
Else
Return Nothing
End If
End Function
I was trying to make a generic function out of this, but couldn't do it. How can I make a generic function that will take a specific T and make it a Nullable(of T)?