Dynamically creating a object

  • Thread starter Thread starter Vannela
  • Start date Start date
V

Vannela

In unmanaged application
CREATE USING allows your application to choose the object
type dynamically. It is usually used to instantiate an
ancestor variable with an instance of one of its
descendants. The particular descendant is chosen at
execution time.
For example, if uo_a has two descendants: uo_a_desc1 and
uo_a_desc2, then the application can select the object to
be created based on current conditions:

uo_a uo_a_var

string ls_objectname

IF ... THEN
ls_objectname = "uo_a_desc1"
ELSE
ls_objectname = "uo_a_desc2"
END IF
uo_a_var = CREATE USING ls_objectname



How can we achieve this in managed code ie., in C#.






Thank you
 
Vannela said:
In unmanaged application
CREATE USING allows your application to choose the object
type dynamically. It is usually used to instantiate an
ancestor variable with an instance of one of its
descendants. The particular descendant is chosen at
execution time.
For example, if uo_a has two descendants: uo_a_desc1 and
uo_a_desc2, then the application can select the object to
be created based on current conditions:

uo_a uo_a_var

string ls_objectname

IF ... THEN
ls_objectname = "uo_a_desc1"
ELSE
ls_objectname = "uo_a_desc2"
END IF
uo_a_var = CREATE USING ls_objectname

How can we achieve this in managed code ie., in C#.

I believe you're after Activator.CreateInstance.
 
Back
Top