예제 #1
0
        private static string AddInitialization(MatchCollection matches, string result, string instanceName)
        {
            foreach (Match match in matches)
            {
                for (int i = 1; i < match.Groups.Count; i++)
                {
                    if (EvalHelper.IsGroupNameANumber(match, i))
                    {
                        continue;
                    }

                    if (EvalHelper.GroupHasNoValue(match, i))
                    {
                        continue;
                    }

                    string groupName = match.Groups[i].Name;

                    PropertyType type    = EvalHelper.GetPropertyType(match.Groups[i].Value);
                    string       typeStr = EvalHelper.GetPropertyTypeStr(type);
                    result += $"    {instanceName}.{groupName} = RegexHelper.GetValue<{typeStr}>(matches, \"{groupName}\");" + Environment.NewLine;
                }
            }

            return(result);
        }
예제 #2
0
        private static string AddProperties(MatchCollection matches, string result)
        {
            foreach (Match match in matches)
            {
                for (int i = 1; i < match.Groups.Count; i++)
                {
                    if (EvalHelper.IsGroupNameANumber(match, i))
                    {
                        continue;
                    }

                    if (EvalHelper.GroupHasNoValue(match, i))
                    {
                        continue;
                    }

                    string groupName = match.Groups[i].Name;

                    PropertyType type    = EvalHelper.GetPropertyType(match.Groups[i].Value);
                    string       typeStr = EvalHelper.GetPropertyTypeStr(type);
                    result += $"  public {typeStr} {groupName} " + "{ get; set; }" + Environment.NewLine;
                }
            }

            return(result);
        }
예제 #3
0
        string GetTypeString(Match match, int i)
        {
            string value = match.Groups[i].Value;

            if (EvalHelper.GetPropertyType(value) == PropertyType.Double)
            {
                return(" (double)");
            }

            return(" (string)");
        }
예제 #4
0
        void GenerateCode()
        {
            if (textToMatch == null)
            {
                HideBlueCheckRedX();
                tbxGroupResults.Text = "";
                return;
            }
            if (regex.IsMatch(textToMatch))
            {
                blueCheck.Visibility = Visibility.Visible;
                redX.Visibility      = Visibility.Collapsed;
                MatchCollection matches = regex.Matches(textToMatch);
                tbxGroupResults.Text = "";
                foreach (Match match in matches)
                {
                    for (int i = 1; i < match.Groups.Count; i++)
                    {
                        string groupName = string.Empty;
                        if (EvalHelper.IsGroupNameANumber(match, i))
                        {
                            continue;
                        }
                        groupName = match.Groups[i].Name;

                        if (EvalHelper.GroupHasNoValue(match, i))
                        {
                            continue;
                        }

                        string type  = "";                         // GetTypeString(match, i);
                        string value = match.Groups[i].Value;
                        if (EvalHelper.GetPropertyType(value) == PropertyType.String)
                        {
                            value = $"\"{value}\"";
                        }
                        tbxGroupResults.Text += $"{groupName} = {value}{type}{Environment.NewLine}";
                    }
                }
                tbxCodeGen.Text = godeGenerator.GenerateCode(matches, tbxRegExPattern.Text, tbxClassName.Text, tbxText.Text, includeRegExHelper);
            }
            else              // We don't have a match.
            {
                tbxGroupResults.Text = "";
                blueCheck.Visibility = Visibility.Collapsed;
                redX.Visibility      = Visibility.Visible;
            }
        }