本文整理汇总了C#中Microsoft.CSharp.CSharpCodeProvider.IsValidIdentifier方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpCodeProvider.IsValidIdentifier方法的具体用法?C# CSharpCodeProvider.IsValidIdentifier怎么用?C# CSharpCodeProvider.IsValidIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CSharp.CSharpCodeProvider
的用法示例。
在下文中一共展示了CSharpCodeProvider.IsValidIdentifier方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
internal static void Main()
{
StringBuilder input = GetInput();
string code = input.ToString();
code = RemoveObjectInitialization(code);
code = RemoveStrings(code);
string[] methods = Regex.Split(code, @"\bstatic\b").ToArray();
Regex validMethod = new Regex(@"\b[_A-Za-z\@][A-Za-z_0-9]*\s*\(");
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
List<string> invokes = new List<string>();
StringBuilder result = new StringBuilder();
foreach (var method in methods)
{
foreach (Match match in validMethod.Matches(method))
{
string identifier = match.ToString().Trim('(').Trim();
if (codeProvider.IsValidIdentifier(identifier))
{
invokes.Add(identifier);
}
}
AppendToResult(invokes, result);
invokes.Clear();
}
Console.WriteLine(result.ToString());
}
示例2: IsValidCSharpIdentifier
/// <summary>
/// Determines of the given value is a valid C# identifier.
/// </summary>
public static bool IsValidCSharpIdentifier(string value)
{
Guard.NotNull(() => value, value);
using (CSharpCodeProvider provider = new CSharpCodeProvider())
{
return provider.IsValidIdentifier(value);
}
}
示例3: IsResourceNameValid
private bool IsResourceNameValid(string name)
{
if (string.IsNullOrEmpty(name))
return false;
if (name[name.Length - 1] == _namespaceSeparator)
return false;
string[] parts = name.Split(_namespaceSeparator);
if (parts.Length == 0)
return false;
var prov = new CSharpCodeProvider();
foreach (string part in parts)
if (!prov.IsValidIdentifier(part))
return false;
return true;
}
示例4: ValidateFieldName
protected virtual string ValidateFieldName(string fieldName)
{
using (var provider = new CSharpCodeProvider())
{
if (!provider.IsValidIdentifier(fieldName))
{
var huh = provider.CreateValidIdentifier(fieldName);
fieldName = string.Format("invalidName_{0}", fieldName);
}
}
return fieldName;
}
示例5: ScrubName
protected virtual string ScrubName(string name)
{
var invalidChars
= new Regex(@"[^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Nl}\p{Mn}\p{Mc}\p{Cf}\p{Pc}\p{Lm}]");
name = invalidChars.Replace(name, string.Empty);
using (var codeProvider = new CSharpCodeProvider())
{
if (!char.IsLetter(name[0])
|| !codeProvider.IsValidIdentifier(name))
{
name = "_" + name;
}
}
return name;
}
示例6: UpdateXamlCodeFromName
private void UpdateXamlCodeFromName()
{
// Change the name of the generated activity class. Our compiler generates C# projects to compile workflows,
// so if it's an invalid C# identifier we use a unique synthetic name, otherwise use the FullName
// of the ModelItem (for example Microsoft.Support.Activities.MyActivity1)
var modelService = WorkflowDesigner.Context.Services.GetService<ModelService>();
using (CSharpCodeProvider csharpCodeProvider = new CSharpCodeProvider())
{
if (modelService != null)
{
if (IsService)
{
var builderName = modelService.Root.Properties[Name_NameProperty];
var builderConfigurationName = modelService.Root.Properties[Name_ConfigurationPropery];
var trimmedName = (Name ?? DefaultWorkflowName).Replace(WhiteSpace, string.Empty);
var newName = XName.Get(trimmedName, XmlNamespace);
if (!object.Equals(builderName.Value.IfNotNull(v => v.GetCurrentValue()), newName))
{
builderName.SetValue(newName);
builderConfigurationName.SetValue(Name);
// The new XAML from the name change should be copied to WorkflowItem.XamlCode
RefreshXamlCodeFromDesigner();
}
}
else
{
string newName = (
csharpCodeProvider.IsValidIdentifier(Name) // CSharpCodeProvider is lightweight, no need to cache
? FullName
: string.Format(WorkflowNamePerfix, Guid.NewGuid().ToString().Replace(Dash, string.Empty)));
var builderName = modelService.Root.Properties[Name_NameProperty];
if (!object.Equals(builderName.Value.IfNotNull(v => v.GetCurrentValue()), newName))
{
builderName.SetValue(newName);
// The new XAML from the name change should be copied to WorkflowItem.XamlCode
RefreshXamlCodeFromDesigner();
}
}
}
}
}