Instance a class at runtime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ernesto Díaz

    #1

    Instance a class at runtime

    Hi

    I need to instance a class at runtime, at runtime I can get the name in a
    string, i would like to know if its possible to instance the class at
    runtime with the name in a string.

    Thanks for your assistance.

    Ernesto Díaz


  • Tim Wilson

    #2
    Re: Instance a class at runtime

    You can get the Type using Type.GetType(st ring) and then you can use one of
    the CreateInstance methods of the Activator class.
    http://msdn.microsoft.com/library/de...ancetopic1.asp

    --
    Tim Wilson
    ..NET Compact Framework MVP

    "Ernesto Díaz" <jediaz@vianney .com.mx> wrote in message
    news:ePpgyKKOGH A.2828@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hi
    >
    > I need to instance a class at runtime, at runtime I can get the name in a
    > string, i would like to know if its possible to instance the class at
    > runtime with the name in a string.
    >
    > Thanks for your assistance.
    >
    > Ernesto Díaz
    >
    >[/color]


    Comment

    • Stoitcho Goutsev \(100\)

      #3
      Re: Instance a class at runtime

      Ernesto,
      You can use the Activator.Creat eInstance or you can use reflection the get
      the constructor and invoke it.


      --

      Stoitcho Goutsev (100)

      "Ernesto Díaz" <jediaz@vianney .com.mx> wrote in message
      news:ePpgyKKOGH A.2828@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Hi
      >
      > I need to instance a class at runtime, at runtime I can get the name in a
      > string, i would like to know if its possible to instance the class at
      > runtime with the name in a string.
      >
      > Thanks for your assistance.
      >
      > Ernesto Díaz
      >
      >[/color]


      Comment

      • KH

        #4
        RE: Instance a class at runtime

        See Assembly.GetTyp e() and Activator.Creat eInstance()


        "Ernesto Díaz" wrote:
        [color=blue]
        > Hi
        >
        > I need to instance a class at runtime, at runtime I can get the name in a
        > string, i would like to know if its possible to instance the class at
        > runtime with the name in a string.
        >
        > Thanks for your assistance.
        >
        > Ernesto Díaz
        >
        >
        >[/color]

        Comment

        • Ernesto Díaz

          #5
          Re: Instance a class at runtime

          Does anybody have an example to help me understand ?

          Thanks

          Ernesto Díaz


          Comment

          Working...