473,386 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to resolve alias to Namespace or type in C#

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
5 2807
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
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
thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..

Nov 16 '05 #4
thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..

Nov 16 '05 #5
thanks.... sounds like there are no real alternatives..... The
Hashtable method will do..

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Matt Mastracci | last post by:
It seems like the C# compile can't resolve the difference between a namespace and a class in a situation that is clearly unambiguous. Note that it sees the namespace "C" before the class "C". I...
5
by: Subrahmanyam Arya | last post by:
Dear oracle gurus, I am unable to get past the error ORA-12154: TNS: could not resolve service name on my host when using hsodbc to talk to a remote mysql database. i got from the meta link all...
10
by: Kimmo Laine | last post by:
Hi, i try to define alias and then use it in another file like this: // ---------- // file: a.cs using System; using MyAlias = MyNamespace.MyClass;
5
by: Jon Shemitz | last post by:
I'm playing with 2.0's extern alias declarations and the :: operator. If I have an extern alias My; and the My namespace contains a TypeName, I can refer to My::TypeName .... or to...
1
by: Hennesey | last post by:
Hello all, I am developing a Visual Studio .Net 2005 application that consumes an Axis 1.3 web service. Importing the WSDL file generates an error "cannot resolve apachesoap:Map type" ...
6
by: Maxim | last post by:
Hello, everybody! I'd like to make global type alias. If I used c++ I would write the following code to create a global type alias: typedef SomeType MyAlias; I've found that using keyword...
3
by: Sharon | last post by:
There is an built-in types table for .NET framework type to C# type which are aliases of predefined types in the System namespace (http://msdn2.microsoft.com/en-US/library/ya5y69ds.aspx). How...
59
by: peter.tornqvist | last post by:
Maybe I'm stupid or maybe I am missing the obvious, but I can't find a way to define a type alias in C# for primitive types (class and interfaces I can inherit from, no problem). I.e I want to...
5
by: carlpayne1984 | last post by:
Hi all, I'm fairly new to XML, however already I have studied myself stupid without being able to solve this problem. Basically, I have an XML file/Schema about a CD catalog that I've created that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.