J
Just D.
All,
Do we have a simple way to Create an object on the fly knowing just an
object type? The usual design-time way is to write a code something like
this:
CObjectType obj = new CObjectType();
That's simple. But to create any object knowing its object type on the fly
is looking like a problem. I'll try to explain the idea.
We have some base class with the method:
Deserialize(string sXML, ref obj, System.Type systemtype)
{
....
}
The idea is to create any object of required type, the type should be
defined through the interface, then to do some appropriate steps to get the
data from the XML string and assign all required properties of the created
object. The idea is simple, but realization... The worst scenario is to use
a switch by systemtype and create all required objects inside an appropriate
switch case. The method is terrible because it's not nice, looking terribly
and absolutely not flexible. But to do the method universal we need to
create a new object on the fly using something like:
systemtype obj = new systemtype();
where "systemtype" is the variable received as a method parameter.
The problem that writing this we're getting a non-workable code.
Any idea or solution? Maybe we could use a virtual method to do this thing
or some other trick?
Thanks,
Just D.
Do we have a simple way to Create an object on the fly knowing just an
object type? The usual design-time way is to write a code something like
this:
CObjectType obj = new CObjectType();
That's simple. But to create any object knowing its object type on the fly
is looking like a problem. I'll try to explain the idea.
We have some base class with the method:
Deserialize(string sXML, ref obj, System.Type systemtype)
{
....
}
The idea is to create any object of required type, the type should be
defined through the interface, then to do some appropriate steps to get the
data from the XML string and assign all required properties of the created
object. The idea is simple, but realization... The worst scenario is to use
a switch by systemtype and create all required objects inside an appropriate
switch case. The method is terrible because it's not nice, looking terribly
and absolutely not flexible. But to do the method universal we need to
create a new object on the fly using something like:
systemtype obj = new systemtype();
where "systemtype" is the variable received as a method parameter.
The problem that writing this we're getting a non-workable code.
Any idea or solution? Maybe we could use a virtual method to do this thing
or some other trick?
Thanks,
Just D.