Dynamically creating a object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vannela

    #1

    Dynamically creating a object

    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
  • Jon Skeet [C# MVP]

    #2
    Re: Dynamically creating a object

    Vannela <anonymous@disc ussions.microso ft.com> wrote:[color=blue]
    > 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#.[/color]

    I believe you're after Activator.Creat eInstance.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Dynamically creating a object

      Vannela <anonymous@disc ussions.microso ft.com> wrote:[color=blue]
      > 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#.[/color]

      I believe you're after Activator.Creat eInstance.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      Working...