How to resolve alias to Namespace or type in C#

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

cody

You have to write it yourself and do not believe you can come from a c#
keyword to a cts type.
 
J

Jon Skeet [C# MVP]

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

Joe Bloggs

thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..
 
J

Joe Bloggs

thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..
 
J

Joe Bloggs

thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top