473,322 Members | 1,538 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,322 software developers and data experts.

Converting form C# alias type to .NET framework type

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 can use access and use this table (by C# code) to convert the alias to
the .NET framework type.

For example: if I have:
string aliasType = "int";
string frameworkType = ???
-------
Thanks
Sharon
Nov 1 '06 #1
3 2548
Hi Sharon,

I'm not exactly sure how to do it using CodeDom, although I suspect that it's
possible, but here's a custom solution that should work just fine (2.0
framework):

System.Collections.Generic.Dictionary<string, stringcSharpTokens =
new System.Collections.Generic.Dictionary<string, string>();

cSharpTokens.Add("bool", "System.Boolean");
cSharpTokens.Add("byte", "System.Byte");
cSharpTokens.Add("sbyte", "System.SByte");
cSharpTokens.Add("char", "System.Char");
cSharpTokens.Add("decimal", "System.Decimal");
cSharpTokens.Add("double", "System.Double");
cSharpTokens.Add("float", "System.Single");
cSharpTokens.Add("int", "System.Int32");
cSharpTokens.Add("uint", "System.UInt32");
cSharpTokens.Add("long", "System.Int64");
cSharpTokens.Add("ulong", "System.UInt64");
cSharpTokens.Add("object", "System.Object");
cSharpTokens.Add("short", "System.Int16");
cSharpTokens.Add("ushort", "System.UInt16");
cSharpTokens.Add("string", "System.String");

Type type = Type.GetType(cSharpTokens["int"]);

Console.WriteLine(type.FullName);

Output:

System.Int32

--
Dave Sexton

"Sharon" <Sh*****@newsgroups.nospamwrote in message
news:E6**********************************@microsof t.com...
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 can use access and use this table (by C# code) to convert the alias to
the .NET framework type.

For example: if I have:
string aliasType = "int";
string frameworkType = ???
-------
Thanks
Sharon

Nov 1 '06 #2
I'm also convinced this will work.
But I'm using .NET framework 1.1 (I can use any hashtable in 1.1 as well)
and this solution does not use the built-in table.

The trick is to work with the .NET framework built-in table.

There must be a way to it. No ?!
--
Thanks
Sharon
Nov 1 '06 #3
Hi Sharon,

There is no built-in table as far as I'm concerned. That information is
proprietary to the compiler.

As I said, CodeDom may offer some mechanism to serialize C# tokens but I
wouldn't recommend that over hard-coding the Hashtable anyway.

Are you worried that they're going to change the tokens in the next release of
the framework? ;)

--
Dave Sexton

"Sharon" <Sh*****@newsgroups.nospamwrote in message
news:3D**********************************@microsof t.com...
I'm also convinced this will work.
But I'm using .NET framework 1.1 (I can use any hashtable in 1.1 as well)
and this solution does not use the built-in table.

The trick is to work with the .NET framework built-in table.

There must be a way to it. No ?!
--
Thanks
Sharon

Nov 1 '06 #4

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

Similar topics

9
by: Rick Cook | last post by:
I would like to do a response form on one of my sites instead of posting an e-mail address for spammers. I've taken a couple of examples from sites, but the code looks clunky and non-conformant to...
10
by: Doug O'Leary | last post by:
Hey, all. I have a perl script which generates the html listed below. I cleaned it up a bit since the perl CGI module creates some really ugly html code. I've looked at this thing 8 ways to...
1
by: Susan Bricker | last post by:
Greetings. I am trying to position opened forms so that they are cascaded on the screen. I have discovered the movesize action (for the DoCmd) and Move property of a form (for Acc 2002/2003). ...
6
by: lauren quantrell | last post by:
I have a command button on a continuous subform and I want the user to click it to open a small popup form that opens in the position of the mouse (which is the same as the position of the command...
11
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
6
by: canoewhiteh2o | last post by:
I am converting a couple of C header files to C#. It is mainly just a bunch C structs but I am not sure how to handle the #ifdef and #ifndef in C#. For example: #ifndef DATE_TIME #define...
0
by: kloplop321 | last post by:
I found this code(vb only) and it does about the same thing(in vb, not vb .NET 2005) Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.