mam 3 podobne funkcje, które zmieniają się w zależności jedynie od typu numerycznego:Tworzenie ogólny sposób przekształcania ciąg liczb pustych
<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
starałem się uczynić rodzajowe funkcji się z tego, ale nie mógł Zrób to. Jak mogę utworzyć funkcję ogólną, która zajmie określoną T i sprawi, że będzie Nullable (of T)?
To źle, nie ma metody Convert.TryChangeType, która zapisywałaby konieczność jedzenia wyjątku, gdy ciąg wejściowy nie jest prawidłowy. – jjxtra