本文整理汇总了C#中ICodeGenerator.IsValidIdentifier方法的典型用法代码示例。如果您正苦于以下问题:C# ICodeGenerator.IsValidIdentifier方法的具体用法?C# ICodeGenerator.IsValidIdentifier怎么用?C# ICodeGenerator.IsValidIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICodeGenerator
的用法示例。
在下文中一共展示了ICodeGenerator.IsValidIdentifier方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateIdName
// given a variable name, this method will check to see if the
// name is a valid identifier name. if this is not the case, then
// at the moment will replace all the blank space with underscores.
public static string GenerateIdName(string name, ICodeGenerator codeGen) {
if (codeGen.IsValidIdentifier(name)) {
return name;
}
string ret = name.Replace(' ', '_');
if (! codeGen.IsValidIdentifier(ret)) {
ret = "_" + ret;
UnicodeCategory unc;
for (int i = 1; i < ret.Length; i++) {
unc = Char.GetUnicodeCategory(ret[i]);
if (
UnicodeCategory.UppercaseLetter != unc &&
UnicodeCategory.LowercaseLetter != unc &&
UnicodeCategory.TitlecaseLetter != unc &&
UnicodeCategory.ModifierLetter != unc &&
UnicodeCategory.OtherLetter != unc &&
UnicodeCategory.LetterNumber != unc &&
UnicodeCategory.NonSpacingMark != unc &&
UnicodeCategory.SpacingCombiningMark != unc &&
UnicodeCategory.DecimalDigitNumber != unc &&
UnicodeCategory.ConnectorPunctuation != unc
) {
ret = ret.Replace(ret[i], '_');
} // if
} // for
}
return ret;
}
示例2: GenerateIdName
public static string GenerateIdName(string name, ICodeGenerator codeGen)
{
if (codeGen.IsValidIdentifier(name))
{
return name;
}
string str = name.Replace(' ', '_');
if (!codeGen.IsValidIdentifier(str))
{
str = "_" + str;
for (int i = 1; i < str.Length; i++)
{
UnicodeCategory unicodeCategory = char.GetUnicodeCategory(str[i]);
if (((((unicodeCategory != UnicodeCategory.UppercaseLetter) && (UnicodeCategory.LowercaseLetter != unicodeCategory)) && ((UnicodeCategory.TitlecaseLetter != unicodeCategory) && (UnicodeCategory.ModifierLetter != unicodeCategory))) && (((UnicodeCategory.OtherLetter != unicodeCategory) && (UnicodeCategory.LetterNumber != unicodeCategory)) && ((UnicodeCategory.NonSpacingMark != unicodeCategory) && (UnicodeCategory.SpacingCombiningMark != unicodeCategory)))) && ((UnicodeCategory.DecimalDigitNumber != unicodeCategory) && (UnicodeCategory.ConnectorPunctuation != unicodeCategory)))
{
str = str.Replace(str[i], '_');
}
}
}
return str;
}