Dynamically create objects and set properties?

  • Thread starter Thread starter donal.conlon
  • Start date Start date
D

donal.conlon

Here's what I'm trying to do:

Have an xml config file like:

<ObjCollection>
<object assembly = "myAssembly.dll,version,neutral,pkt"
typeName="MyObject" title="" description=""/>
</ObjCollection>

I want to be able to read all the objects listed in this config file,
and be able to create objects from them and set their properties from
the attributes.

someit like:

object obj =
Activator.CreateInstance(xmlNode.attributes["assembly"].value,xmlNode.attributes["typeName"].value);

obj.Title = xmlNode.attributes["title"].value;
.....


Is this at all possible?

Cheers

donal
 
im working on doing something similar with an sql server i havent found
a way taht works yet ...
 
temp = Activator.CreateInstance(o.GetType());
//o.GetType().InvokeMember("", BindingFlags.CreateInstance, null,
null, null);

this is what i tryed so far no luck i always get the same mistake

Cannot widen from target type to primitive type.
 
I dont think it makes a difference because mine is also for a web app
but in my case its in a component
 
donal.conlon said:
Here's what I'm trying to do:

Have an xml config file like:

<ObjCollection>
<object assembly = "myAssembly.dll,version,neutral,pkt"
typeName="MyObject" title="" description=""/>
</ObjCollection>

I want to be able to read all the objects listed in this config file,
and be able to create objects from them and set their properties from
the attributes.

This sounds like the kind of thing we do in Spring in Java - and
there's a .NET version of Spring too:

http://www.springframework.net/
 
Back
Top