By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,566 Members | 1,820 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,566 IT Pros & Developers. It's quick & easy.

How to resolve alias to Namespace or type in C#

P: n/a
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"

Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


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

"Joe Bloggs" <es***@rocketmail.com> schrieb im Newsbeitrag
news:11*********************@g14g2000cwa.googlegro ups.com...
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"

Nov 16 '05 #2

P: n/a
Joe Bloggs <es***@rocketmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

P: n/a
thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..

Nov 16 '05 #4

P: n/a
thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..

Nov 16 '05 #5

P: n/a
thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.