Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 170215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:46:07+00:00 2026-05-11T12:46:07+00:00

Is there a way, in .net, to detect if a word is a keyword

  • 0

Is there a way, in .net, to detect if a word is a keyword in a given .net language?

I am using a fairly simple code generator for this project, and I would like to start automating it. Right now I do each one by hand, so fixing any issues that arise is pretty easy. However, once this starts happening automatically I am going to need a way to detect if a word I need to use as an identifier is a keyword. I can still use it, I just need to quote it properly.

I know that I can simply quote everything I generate, but I would like to keep the generated code pretty 🙂

An example of the kind of things I need to quote:

vb:  Public [Class] As String = 'CLASS' c#:  public String @class = 'CLASS'; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:46:07+00:00Added an answer on May 11, 2026 at 12:46 pm

    Perhaps you’re looking for IsValidIdentifier

    [IsValidIdentifier] return[s] true only if the value fits the rules of the language and does not conflict with a keyword.

    or CreateEscapedIdentifier

    CreateEscapedIdentifier tests whether the identifier conflicts with any reserved or language keywords, and if so, returns an equivalent name with language-specific escape code formatting

    For example:

        CSharpCodeProvider csProvider = new CSharpCodeProvider();      bool isValid1 = csProvider.IsValidIdentifier('class');     // returns false      string escapedId1 = csProvider.CreateEscapedIdentifier('foo');     // escapedId1 = 'foo'     string escapedId2 = csProvider.CreateEscapedIdentifier('do');     // escapedId2 = '@do'     string escapedId3 = csProvider.CreateEscapedIdentifier('AndAlso');     // escapedId3 = 'AndAlso' (not reserved in c#)      VBCodeProvider vbProvider = new VBCodeProvider();      string escapedId4 = vbProvider.CreateEscapedIdentifier('AndAlso');     // escapedId4  = '[AndAlso]' (reserved in VB) 

    Seems like it wouldn’t be too hard to extend/use this facility to meet your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to detect page refresh without using viewstate in asp.net webforms
I've got one quick question. Is there any simple way to detect if .net
Is there an easy way to detect when a .NET app gets or loses
Is there a way using the Net::SFTP Library in Ruby ( API Link )
Question: Is there a way to detect what XHtml conformance setting a particular ASP.Net
Is there a way to detect BlackBerry Model in asp.net, I have made some
Using .NET, is there a way to retrieve the external IP of a PC
Is there a way to detect the actual width of text in a vb.net
I have an assembly. Is there a way to detect which version of .NET
Is there a way in .NET 3.0 (or earlier) to get a string representation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.