当前位置: 首页>>代码示例>>C#>>正文


C# CSharpCodeProvider.IsValidIdentifier方法代码示例

本文整理汇总了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());
        }
开发者ID:RuzmanovDev,项目名称:TelerikAcademy,代码行数:34,代码来源:Konspiration.cs

示例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);
            }
        }
开发者ID:NuPattern,项目名称:NuPattern,代码行数:12,代码来源:DataFormats.cs

示例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;
		}
开发者ID:rsdn,项目名称:janus,代码行数:15,代码来源:ResourceNameForm.cs

示例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;
 }
开发者ID:jacksoncougar,项目名称:Moonfish-Editor,代码行数:12,代码来源:GuerillaBase.cs

示例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;
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:18,代码来源:CSharpMigrationCodeGenerator.cs

示例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();
                        }
                    }
                }
            }
        }
开发者ID:barbarossia,项目名称:CWF,代码行数:44,代码来源:WorkflowEditorViewModel.cs


注:本文中的Microsoft.CSharp.CSharpCodeProvider.IsValidIdentifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。