read xml and create object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have a xml file which include object name and its property.

<objectname>TextBox1</objectname>
<property>Text</property>

how can i get the property source in c# ? . I have to create an object from
string data type like TextBox1.Text . I wonder that if it is possible or not.

regards.
 
Do you mean to say that you have some UI controls, and @ run time, you want
to set some properties of those controls to values from the XML file? If yes,
you could easily use Reflection to accomplish that.
 
Hi,

You can use reflection to do this, but you will also need state the type of
the control to create, this unless ALL controls are of the same type.
You use Activator.CreateInstance() to create the object and later assign the
properties using reflection.


Cheers,
 
can you give me example ?

Ignacio Machin \( .NET/ C# MVP \) said:
Hi,

You can use reflection to do this, but you will also need state the type of
the control to create, this unless ALL controls are of the same type.
You use Activator.CreateInstance() to create the object and later assign the
properties using reflection.


Cheers,
 
Back
Top