Eğer Reflection ile Nullable(Of T),Nullable
şeklinde hata alırsınız.
Aşağıdaki fonksiyon ile tipi değiştirip değeri setleyebiliriz:
Private Function _TipDegistir(ByVal deger As Object, ByVal hedefTip As System.Type) As Object
If hedefTip Is Nothing Then Throw New ArgumentException("Hedef Tip tanımsız")
If deger.GetType Is (hedefTip) Then
Return deger
End If
If hedefTip.IsGenericType Then
If hedefTip.GetGenericTypeDefinition().Equals(GetType(Nullable(Of ))) Then
If deger Is Nothing Then Return Nothing
Dim c As New System.ComponentModel.NullableConverter(hedefTip)
hedefTip = c.UnderlyingType
End If
End If
Return Convert.ChangeType(deger, hedefTip)
End Function
Örneğin :
propertyInfoObject.SetValue(refObject, _TipDegistir(1,System.Nullable(Of Integer), Nothing)