是否有一个.NET函数来验证一个类名? [英] Is there a .NET function to validate a class name?

查看:199
本文介绍了是否有一个.NET函数来验证一个类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用codeDOM生成基于用户价值的动态code。其中的一个值的控制什么,我产生了类的名称是。我知道我可以消毒根据有关使用常规EX pressions有效的类名称的语言规则的名字,但我想知道是否有内置的框架,具体的方法来验证和/或消毒类名。

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)

这篇关于是否有一个.NET函数来验证一个类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆