8
Type.GetType("System.String")

Is there a lookup for the aliases available somewhere?

Type.GetType("string")

returns null.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
David
  • 19,389
  • 12
  • 63
  • 87

3 Answers3

17

This is not possible programmatically, since the 'aliases' are in fact keywords introduced in C#, and Type.GetType (like every other framework method) is part of the language-independent framework.

You could create a dictionary with the following values:

    bool      System.Boolean
    byte      System.Byte
    sbyte     System.SByte
    char      System.Char
    decimal   System.Decimal
    double    System.Double
    float     System.Single
    int       System.Int32
    uint      System.UInt32
    long      System.Int64
    ulong     System.UInt64
    object    System.Object
    short     System.Int16
    ushort    System.UInt16
    string    System.String
configurator
  • 40,828
  • 14
  • 81
  • 115
2

The "aliases" are part of the language definition. You need to look them up in the language spec in question. They are compiled away, and don't exist at runtime - string becomes System.String, int becomes System.Int32, etc.

Barry Kelly
  • 41,404
  • 5
  • 117
  • 189
2

Aliases (int, bool etc.) are not defined in CLS. They're just compile-time constants, that are replaced at runtime. This means that by the time your program is running, and you can do things "programmatically, aliases are already gone. You can only do something like this:

Type.GetType(typeof (string).ToString())
Mindaugas Mozūras
  • 1,461
  • 2
  • 17
  • 29