M
Matt Weaver
I'm trying to setup a sub that would assign the properties of a
webcontrol based on data in a table. I've setup a routine which looks
like this:
Private Sub SetObjectProperty(ByRef obj As Object, _
ByValPropertyName As String, _
ByVal PropertyValue As String)
Dim wType As System.Type = obj.GetType
Dim wProp As Reflection.PropertyInfo = _
wType.GetProperty(PropertyName)
wProp.SetValue(obj, PropertyValue, Nothing)
End Sub
It works well when the property is a string, but when it's boolean I get
this error: "Object of type 'System.String' cannot be converted to
type 'System.Boolean'"
I can get the type of the property (in this case, System.Boolean), I
have the value I'd get if I used .ToString(). .NET has to have some
function that'd dynamically cast the string back to Boolean (or whatever
data type), right? I'm trying to avoid a giant if-then structure (if
type = system.boolean then cast as boolean).
TIA!
-Matt
webcontrol based on data in a table. I've setup a routine which looks
like this:
Private Sub SetObjectProperty(ByRef obj As Object, _
ByValPropertyName As String, _
ByVal PropertyValue As String)
Dim wType As System.Type = obj.GetType
Dim wProp As Reflection.PropertyInfo = _
wType.GetProperty(PropertyName)
wProp.SetValue(obj, PropertyValue, Nothing)
End Sub
It works well when the property is a string, but when it's boolean I get
this error: "Object of type 'System.String' cannot be converted to
type 'System.Boolean'"
I can get the type of the property (in this case, System.Boolean), I
have the value I'd get if I used .ToString(). .NET has to have some
function that'd dynamically cast the string back to Boolean (or whatever
data type), right? I'm trying to avoid a giant if-then structure (if
type = system.boolean then cast as boolean).
TIA!
-Matt