M
MarkusJ_NZ
Hi, I am trying to dynamically populate an objects properties using
reflection.
Specifically, I have an object called the theObj and it has a number
of properties.
property is a PropertyInfo object
What I want to do is to be able to set the property value dynamically
which I am doing so using this line of code (Simplified version below)
property.SetValue(theObj, TextBox1.Text, null);
The above works fine if the property is of type String as the item
TextBox1.Text returns a string.
If however, the property is of type Int32, DateTime etc it fails...
What I need to do is to cast the value returned from the TextBox.Text
(string) to the data type the property expects..
something like this
(This does not work)
property.SetValue(theObj, ((property.GetType())TextBox1.Text), null);
Any help appreciated
Thanks
Markus
reflection.
Specifically, I have an object called the theObj and it has a number
of properties.
property is a PropertyInfo object
What I want to do is to be able to set the property value dynamically
which I am doing so using this line of code (Simplified version below)
property.SetValue(theObj, TextBox1.Text, null);
The above works fine if the property is of type String as the item
TextBox1.Text returns a string.
If however, the property is of type Int32, DateTime etc it fails...
What I need to do is to cast the value returned from the TextBox.Text
(string) to the data type the property expects..
something like this
(This does not work)
property.SetValue(theObj, ((property.GetType())TextBox1.Text), null);
Any help appreciated
Thanks
Markus