How Do I...

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

    #1

    How Do I...

    how do I convert a string representation of a system.Type into a System.Type
    object?

    Cheers

    Earth Worm Jim


  • Jon Skeet [C# MVP]

    #2
    Re: How Do I...

    <"Jim" <ssss>> wrote:[color=blue]
    > how do I convert a string representation of a system.Type into a System.Type
    > object?[/color]

    That entirely depends on the string representation and the type
    involved. If you control the type involved, you can use the
    TypeConverter class to do some of the work for you - if you look up
    TypeConverter in the MSDN, you'll find quite a lot of information to
    help you.

    --
    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

    • Ryan

      #3
      Re: How Do I...

      Hi, Jim.

      if you know the fullname of the type, you can get the type like that.
      Type myType1 = Type.GetType("S ystem.Int32");

      regards


      "Jim" <ssss> wrote in message news:OASElfjkDH A.644@TK2MSFTNG P11.phx.gbl...[color=blue]
      > how do I convert a string representation of a system.Type into a[/color]
      System.Type[color=blue]
      > object?
      >
      > Cheers
      >
      > Earth Worm Jim
      >
      >[/color]


      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: How Do I...

        Jon Skeet [C# MVP] <skeet@pobox.co m> wrote:[color=blue]
        > <"Jim" <ssss>> wrote:[color=green]
        > > how do I convert a string representation of a system.Type into a System.Type
        > > object?[/color]
        >
        > That entirely depends on the string representation and the type
        > involved. If you control the type involved, you can use the
        > TypeConverter class to do some of the work for you - if you look up
        > TypeConverter in the MSDN, you'll find quite a lot of information to
        > help you.[/color]

        Apologies - having read Ryan's answer, I see what you mean :)

        Ryan's on the right track - but there is one caveat, which is that when
        Type.GetType is presented with just the type name (and no assembly
        information) it only looks in the current assembly and mscorlib, so
        Type.GetType ("System.Window s.Forms.Form") will return null, for
        instance. If your string contains the full assembly information, that's
        used appropriately - otherwise you can use Assembly.GetTyp e if you know
        the assembly which contains the type you're after.

        Sorry again about the previous reply...

        --
        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...