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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With