本文整理汇总了C#中ICodeGenerator.CreateValidIdentifier方法的典型用法代码示例。如果您正苦于以下问题:C# ICodeGenerator.CreateValidIdentifier方法的具体用法?C# ICodeGenerator.CreateValidIdentifier怎么用?C# ICodeGenerator.CreateValidIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICodeGenerator
的用法示例。
在下文中一共展示了ICodeGenerator.CreateValidIdentifier方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeSafeName
public static string MakeSafeName (string name, ICodeGenerator codeGen)
{
if (name == null || codeGen == null)
throw new NullReferenceException ();
name = codeGen.CreateValidIdentifier (name);
return MakeSafeNameInternal (name);
}
示例2: MakeSafeName
public static string MakeSafeName (string name, ICodeGenerator codeGen)
{
if (name == null || codeGen == null)
throw new NullReferenceException ();
name = codeGen.CreateValidIdentifier (name);
if (name.Length == 0)
return "_";
StringBuilder sb = null;
if (!Char.IsLetter (name, 0) && name [0] != '_') {
sb = new StringBuilder ();
sb.Append ('_');
}
int start = 0;
for (int i = 0; i < name.Length; i++) {
if (!Char.IsLetterOrDigit (name, i)) {
if (sb == null)
sb = new StringBuilder ();
sb.Append (name, start, i - start);
sb.Append ('_');
start = i + 1;
}
}
if (sb != null) {
sb.Append (name, start, name.Length - start);
return sb.ToString ();
}
else
return name;
}