C# keyword list programatically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Could someone please tell me how I can get a list of c# keywords (e.g.
'event') programmatically at runtime?

Many thanks,

Ronnie
 
Ronnie Smith said:
Could someone please tell me how I can get a list of c# keywords (e.g.
'event') programmatically at runtime?

Well, only by having a hard-coded list of them. They're not exposed by
anything in the framework as far as I'm aware.
 
Hello Ronnie,

there is no way for this, they are hard-codded.

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


RS> Hello,
RS>
RS> Could someone please tell me how I can get a list of c# keywords
RS> (e.g. 'event') programmatically at runtime?
RS>
RS> Many thanks,
RS>
RS> Ronnie
RS>
 
Thanks for the reply Jon. I was hoping that there would be a framework
solution since my hardcoded list may no longer be complete at the next .NET
release.

OK - I'll work with the hardcoded list.

Ronnie
 
Ronnie Smith said:
Thanks for the reply Jon. I was hoping that there would be a framework
solution since my hardcoded list may no longer be complete at the next .NET
release.

OK - I'll work with the hardcoded list.

Well, C# 3 is about to come out but I wouldn't expect C# 4 any time
soon, and the C# 3 spec is nailed down now.

There are various *contextual* keywords in C# 3, but no new "real"
keywords as such. What are you wanting to do with the keywords? If it's
something like syntax highlighting, it's worth using the contextual
keywords.
 
Ronnie Smith kirjoitti:
Thanks for the reply Jon. I was hoping that there would be a framework
solution since my hardcoded list may no longer be complete at the next .NET
release.

Why do you need the list? If you are afraid of using keywords in your
code, you can protect them with @ sign, like:

using System;
namespace Keyword{
class Program{
static void Main(string[] args) {
int @int = 2;
int @foo = 4;
Console.WriteLine("values {0} {1}", @int, @foo);
}
}
}

So, you can protect keywords with @, but it does not matter in front of
non keyword.
 
Arto,

I have a tool which can load a c/c++ header file and automatically create a
c# wrapper for the corresponding DLL - allowing the old style DLL to be
accessed from .NET. However sometimes the parameters names are actually c#
keywords. Yes, I could add an underscore or the '@' symbol before each one,
but I thought that the cleaner way would be to preserve the original
parameter names where possible and only ammend them if needed. Hence my
request to programmatically ascertain the c# keywords.

Ronnie

Arto Viitanen said:
Ronnie Smith kirjoitti:
Thanks for the reply Jon. I was hoping that there would be a framework
solution since my hardcoded list may no longer be complete at the next .NET
release.

Why do you need the list? If you are afraid of using keywords in your
code, you can protect them with @ sign, like:

using System;
namespace Keyword{
class Program{
static void Main(string[] args) {
int @int = 2;
int @foo = 4;
Console.WriteLine("values {0} {1}", @int, @foo);
}
}
}

So, you can protect keywords with @, but it does not matter in front of
non keyword.
 
Hi Ronnie,

Thanks for your background information.

The C# language keywords are part of the C# language specification which is
not defined in the .Net Framework(which can target many other languages).
Actually, the CLI will have no knowledge of these C# language keywords.
These C# keywords are built in the C# compiler not the .Net Framework.
Also, certain C# compiler vendor may add its own standard C# language
extension keywords.

So I think you have to build a hard-list for the C# keywords. Hope this
helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Jeffrey,

Thanks for taking the time to explain the issue to me.

Best regards,

Ronnie
 
Back
Top