How to resolve alias to Namespace or type in C#

  • Thread starter Thread starter Joe Bloggs
  • Start date Start date
J

Joe Bloggs

Hi,

I would like to programatically resolve aliases to the actual type,
eg. int to System.Int32.

Essentially, I would like to do this:

Type t = Type.GetType(ResolveAlias("int"));

if (t == typeof(System.Int32))
:
else if (t == typeof(System.Int64)
:
else if (t == typeof(System.Int16))
:


where ResolveAlias("int") will return the string "System.Int32"
 
You have to write it yourself and do not believe you can come from a c#
keyword to a cts type.
 
Joe Bloggs said:
I would like to programatically resolve aliases to the actual type,
eg. int to System.Int32.

Just make a map:

Hashtable aliases = new Hashtable();
aliases["int"] = typeof(int);
aliases["byte"] = typeof(byte);
etc.

There aren't many of them, so it shouldn't take long.
 
thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..
 
thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..
 
thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..
 
Back
Top