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
0
        /// <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
0
		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;
		}
 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;
 }
        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;
        }
        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();
                        }
                    }
                }
            }
        }