Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to get type of an aliased type in c#?

Tags:

c#

c#-3.0

Type.GetType("System.String")

Is there a lookup for the aliases available somewhere?

Type.GetType("string")

returns null.

like image 292
David Avatar asked Nov 26 '08 14:11

David


2 Answers

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
like image 173
configurator Avatar answered Nov 12 '22 09:11

configurator


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.

like image 2
Barry Kelly Avatar answered Nov 12 '22 11:11

Barry Kelly