473,715 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Obtaining c# type declaration


Hi all

I am using reflection to obtain some FieldInfo objects, what I need to do
is convert the .Net type to the c# syntax - I can do this myself using my
own conversion but I was wondering if there was a quick and easy way - example:

Int32 would become int
String would be come string

Any suggestions? Should I just write my own?

Thanks
Kev
Jan 20 '06 #1
9 1421
Lawrence Kevin wrote:
I am using reflection to obtain some FieldInfo objects, what I need to do
is convert the .Net type to the c# syntax - I can do this myself using my
own conversion but I was wondering if there was a quick and easy way - example:

Int32 would become int
String would be come string

Any suggestions? Should I just write my own?


Yes, I don't think there's anything in the framework to do this for
you. Just have a map from Type to name, and use map[typeof(int)]="int";
etc. Then check for the presence of the type within the map, and use
Type.Name if it's not there. There aren't many to do, fortunately.

Jon

Jan 20 '06 #2
> Lawrence Kevin wrote:
I am using reflection to obtain some FieldInfo objects, what I need
to do is convert the .Net type to the c# syntax - I can do this
myself using my own conversion but I was wondering if there was a
quick and easy way - example:

Int32 would become int
String would be come string
Any suggestions? Should I just write my own?

Yes, I don't think there's anything in the framework to do this for
you. Just have a map from Type to name, and use
map[typeof(int)]="int"; etc. Then check for the presence of the type
within the map, and use Type.Name if it's not there. There aren't many
to do, fortunately.

Jon


Thanks

Kev
Jan 20 '06 #3
Hello Lawrence,

No in built functionality to get type specific "primitive type name". Anyway,
there should not be any problem/issues with the ones you get using Reflection.
Otherwise, you might have to write a switch to convert BCL names to language
specific names.

r.

Hi all

I am using reflection to obtain some FieldInfo objects, what I need to
do is convert the .Net type to the c# syntax - I can do this myself
using my own conversion but I was wondering if there was a quick and
easy way - example:

Int32 would become int
String would be come string
Any suggestions? Should I just write my own?

Thanks
Kev

Jan 20 '06 #4
Kev,

I don't understand what the difference is really, since C# will accept
String for "string" and Int32 for "int". They are aliases, and they don't
exclude the type names as they are defined in the framework.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Lawrence Kevin" <sp******@spam. com> wrote in message
news:3a******** *************** **@news.rmplc.c o.uk...

Hi all

I am using reflection to obtain some FieldInfo objects, what I need to do
is convert the .Net type to the c# syntax - I can do this myself using my
own conversion but I was wondering if there was a quick and easy way -
example:

Int32 would become int
String would be come string

Any suggestions? Should I just write my own?

Thanks
Kev

Jan 21 '06 #5
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c om> wrote:
I don't understand what the difference is really, since C# will accept
String for "string" and Int32 for "int". They are aliases, and they don't
exclude the type names as they are defined in the framework.


Sure - but I'm guessing that this could be used for a code-generator or
something similar (documentation system?), where it would produce more
idiomatic C# code if it used "int" instead of "Int32" etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 21 '06 #6
Well, a statement could be made about one who doesn't know the
difference between Int32 and int... =)
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c om> wrote:
I don't understand what the difference is really, since C# will
accept
String for "string" and Int32 for "int". They are aliases, and they
don't
exclude the type names as they are defined in the framework.


Sure - but I'm guessing that this could be used for a code-generator or
something similar (documentation system?), where it would produce more
idiomatic C# code if it used "int" instead of "Int32" etc.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 21 '06 #7
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c om> wrote:
Well, a statement could be made about one who doesn't know the
difference between Int32 and int... =)


Why should it be a matter of knowing differences? Why can't it be a
simple matter of preference and familiarity? The MSDN library gives
declarations using the C# aliases (in the details of the method), and I
believe it's a better product because of that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 21 '06 #8
In the general sense, I couldn't care less, it's all the same to me.

However, when dealing with the code generators, it's a little different,
since you would have to have an option (maybe one exists already, I don't
know, I haven't looked that much into it) to indicate that you should output
aliases.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c om> wrote:
Well, a statement could be made about one who doesn't know the
difference between Int32 and int... =)


Why should it be a matter of knowing differences? Why can't it be a
simple matter of preference and familiarity? The MSDN library gives
declarations using the C# aliases (in the details of the method), and I
believe it's a better product because of that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 21 '06 #9
I'm sticking to the C# keywords purely to follow coding-standards within
our department.

Kev
Kev,

I don't understand what the difference is really, since C# will
accept String for "string" and Int32 for "int". They are aliases, and
they don't exclude the type names as they are defined in the
framework.

"Lawrence Kevin" <sp******@spam. com> wrote in message
news:3a******** *************** **@news.rmplc.c o.uk...
Hi all

I am using reflection to obtain some FieldInfo objects, what I need
to do is convert the .Net type to the c# syntax - I can do this
myself using my own conversion but I was wondering if there was a
quick and easy way - example:

Int32 would become int
String would be come string
Any suggestions? Should I just write my own?

Thanks
Kev

Jan 23 '06 #10

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

Similar topics

6
2744
by: SHC | last post by:
Hi all, I created an application from the Console Application (.NET) of VC++ .NET 2003, and I did "Build" the application of the attached .cpp file, volcanoes.xml and geology.dtd on my VC++ .NET 2003 - Windows XP Pro PC suscessfully. But when I ran it from the command line - C:\Documents and Settings\SHC\My Documents\Visual Studio Projects\XMLdtdValidatingReader\Debug>XMLdtdValidatingReader valcanoes.xml, I got the following message in...
6
2689
by: S.Tobias | last post by:
I'm trying to understand how structure type completion works. # A structure or union type of unknown # content (as described in 6.7.2.3) is an incomplete type. It # is completed, for all declarations of that type, by ^^^ # declaring the same structure or union tag with its defining # content later in the same scope. ^^^^^ (6.2.5#23)
31
2615
by: CeZaR | last post by:
Hi, How can i specify the return type of a function returning a managed array of chars. If i try to write: "char __gc func()" i get an error! How can i do that? Thanks!
4
2143
by: kgpsoftware | last post by:
Hi folks, I have a DLL which contains functions that return __int64 values, but I can't get Visual C to read the return value correctly. I am using the 2003 version. Here is the declare: __int64 __stdcall TEST(void);
4
3391
by: Bill Woodruff | last post by:
< note : this message was sparked in part by comments by David Browne on a previous thread : "inserting an anonymous method as a value in a generic dictionary ?" : David had shown the use of 'Delegate as a valid Type declaration for the Value of a Generic Dictionary. I am curious as to why I can compile and use this syntax : it seems to me to violate the requirement that the Value of a Generic Dictionary be a Type Name.
9
682
by: psujkov | last post by:
Hi everybody, int f(int a, int b) { return a + b; }; is it possible to obtain this function signature - int (int, int) in this case - for use in boost::function_traits ? e.g. std::cout << "f's arity : " << boost::function_traits<*obtaining signature from f()*>::arity << std::endl; please no macro solutions - only C++ (Boost MPL maybe could be useful - but still don't see how)
7
2769
by: =?Utf-8?B?Sm9obiBTdGFnZ3M=?= | last post by:
Hello, Please read this all before giving an answer :) I'm doing some troubleshooting on a web application that my company wrote. It's written in asp.net 1.1. The error that the Event viewer gives is: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
6
14722
by: samsneelam | last post by:
Hi.. This is samuel, while doing a program, i encountered this problem.. Let me give you clarity regarding my prob.. I am having two files .. one is mpcplib.h it contains the follwing declerations.... #include <queue> #include <vector> #include <string> class database { queue<delayTP> delayThrouput;
10
4333
by: tvnaidu | last post by:
I am using Three pthread functions below, I got ISO error, then I declared int variable called val123, then I assigned, but still I am getting error, any idea?. also I included pthread.h. compiling in Linux with GCC. pthread_cond_signal(&(receiverConf->receive_q_cond)); pthread_cond_destroy(&(receiverConf->receive_q_cond)); pthread_mutex_destroy(&(receiverConf->receive_q_lock)); Main.cpp:545: ISO C++ forbids declaration of ` ...
0
8718
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9332
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9195
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9100
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9044
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3174
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2537
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.