Alex Rivera | Logout

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

Asked 2008-09-18T14:07:27.643
21

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.

Edit
Report

1 Answer

2

I found an answer to my question. I can call

CodeCompiler.ValidateIdentifiers(class1);

where class1 is a CodeObject to validate all identifiers in that CodeDom tree and below. So I can call this right after I create my CodeTypeDeclaration class1 to validate just the class name, or I can build up my CodeDom and then call this at the end to validate all the identifiers in my tree. Just what I needed!

answered 2008-09-18T14:19:12.093

Your Answer