Im using Me.GetType.GetProperty("PropName").SetValue(Me, Value, Nothing) to set the value of the property PropName, but, if the type of VALUE is not the same one that that of PropName the method fails, although the value be convertibe.
That is to say, if VALUE is "4" (String) and the type of YY is Long, the method fails.
It is possible to do a casting in this situation?
Thanks anticipated.
Comments
Try using an integer with the Propname. the other value has to be convertible too, I guess.
HTH
Dhruv(Battleguard)
: Im using Me.GetType.GetProperty("PropName").SetValue(Me, Value, Nothing) to set the value of the property PropName, but, if the type of VALUE is not the same one that that of PropName the method fails, although the value be convertibe.
: That is to say, if VALUE is "4" (String) and the type of YY is Long, the method fails.
: It is possible to do a casting in this situation?
: Thanks anticipated.
:
I create code for a base class:
Public MustInherit Class BaseClass
Default Public Property Prop(ByVal PropName As String) As Object
Get
Return Me.GetType.GetProperty(PropName).GetValue(Me, Nothing)
End Get
Set(ByVal Value As Object)
Me.GetType.GetProperty(PropName).SetValue(Me, Value, Nothing)
End Set
End Property
End Class
Next a Derived Class
Public Class DerivedClass
Inherits BaseClass
Private _Value As Long
Private _Text As String
Public Property Value() As Long
Get
Return _Value
End Get
Set(ByVal Value As Long)
_Value = Value
End Set
End Property
Public Property Text() As String
Get
Return _Text
End Get
Set(ByVal Value As String)
_Text = Value
End Set
End Property
End Class
and when I do:
Dim x As New DerivedClass()
x("Value") = "2"
The Program crashes, I can't put the complet error code because I've installed the spanish version of VBNet and my English is not as good as to translate it.
Thank you for reply.
: Hi,
: Try using an integer with the Propname. the other value has to be convertible too, I guess.
:
: HTH
: Dhruv(Battleguard)
:
: : Im using Me.GetType.GetProperty("PropName").SetValue(Me, Value, Nothing) to set the value of the property PropName, but, if the type of VALUE is not the same one that that of PropName the method fails, although the value be convertibe.
: : That is to say, if VALUE is "4" (String) and the type of YY is Long, the method fails.
: : It is possible to do a casting in this situation?
: : Thanks anticipated.
: :
:
: