Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a .NET function to validate a class name?

Tags:

I am using CodeDom to generate dynamic code based on user values. One of those values controls what the name of the class I'm generating is. I know I could sterilize the name based on language rules about valid class names using regular expressions, but I'd like to know if there is a specific method built into the framework to validate and/or sterilize a class name.

like image 427
Zach Avatar asked Sep 18 '08 14:09

Zach


1 Answers

An easy way to determine if a string is a valid identifier for a class or variable is to call the static method

System.CodeDom.Compiler.CodeGenerator.IsValidLanguageIndependentIdentifier(string value) 
like image 192
Micah Avatar answered Oct 03 '22 23:10

Micah