code_junkie

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

Nov 10th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. System.CodeDom.Compiler.CodeGenerator.IsValidLanguageIndependentIdentifier(string value)
  2.  
  3. CSharpCodeProvider codeProvider = new CSharpCodeProvider();
  4. string sFixedName = codeProvider.CreateValidIdentifier( "somePossiblyInvalidName" );
  5. CodeTypeDeclaration codeType = new CodeTypeDeclaration( sFixedName );
  6.  
  7. CodeCompiler.ValidateIdentifiers(class1);
  8.  
  9. public static bool IsReservedKeyWord(string identifier)
  10. {
  11. Microsoft.CSharp.CSharpCodeProvider csharpProvider = new Microsoft.CSharp.CSharpCodeProvider();
  12. return csharpProvider.IsValidIdentifier(identifier);
  13. }
Add Comment
Please, Sign In to add comment