public void AddWarningsForMissingPlaceholders()
 {
     for (int i = 0; i < FormatValues.Count; i++)
     {
         if (!FormatPlaceholders.Contains(i.ToString()))
         {
             ValidationErrors.Add($"Warning: Format value {i} was not found in format placeholders");
             FormatPlaceholders.Add(i.ToString());
         }
     }
 }
        public void ProcessCurrentSection()
        {
            var name             = CurrentSection.ToString();
            var doublePointSplit = name.Split(':');

            if (doublePointSplit.Length > 1)
            {
                name = doublePointSplit[0];
            }
            if (!FormatPlaceholders.Contains(name))
            {
                FormatPlaceholders.Add(name);
            }
            ClearCurrentSection();
        }
Esempio n. 3
0
        private FormatPlaceholders GetFormatPlaceholders(string formatTemplate, int max_count = 100)
        {
            //we return only placeholders with index 0, 1, 2, 3, 4, 5, 6
            //if an index is NOT used, we return null
            var formatTemplateParser = new FormatTemplateParser();


            string.Format(formatTemplateParser, formatTemplate, Enumerable.Range(0, max_count).Cast <object>().ToArray());
            var placeholders = formatTemplateParser.Placeholders;

            var returnValue = new FormatPlaceholders();

            foreach (var placeholder in placeholders)
            {
                switch (placeholder.Index)
                {
                case 0:
                    returnValue.IdentifyingLetter = placeholder;
                    break;

                case 1:
                    returnValue.StartYear = placeholder;
                    break;

                case 2:
                    returnValue.StartMonth = placeholder;
                    break;

                case 3:
                    returnValue.StartDay = placeholder;
                    break;

                case 4:
                    returnValue.EndYear = placeholder;
                    break;

                case 5:
                    returnValue.EndMonth = placeholder;
                    break;

                case 6:
                    returnValue.EndDay = placeholder;
                    break;
                }
            }

            return(returnValue);
        }
        public ParseResult <string, object> GetResult()
        {
            if (FormatValueCountUnequalToFormatPlaceholderCount)
            {
                var result = ParseResult.Error(ValidationErrors.Concat(new[] { $"Format values count ({FormatValues.Count}) is not equal to column placeholders count ({FormatPlaceholders.Count}), see #MISSING# in format placeholders list (keys)" }), FormatPlaceholders.Zip(FormatValues, (name, value) => new KeyValuePair <string, object>(name, value)));
                FormatPlaceholders.AddRange(Enumerable.Range(1, FormatValues.Count - FormatPlaceholders.Count).Select(_ => "#MISSING#"));
                return(result);
            }
            else if (FormatPlaceholderCountUnequalToFormatValueCount)
            {
                var result = ParseResult.Error(ValidationErrors.Concat(new[] { $"Format placeholders count ({FormatPlaceholders.Count}) is not equal to column values count ({FormatValues.Count}), see #MISSING# in format values list (values)" }), FormatPlaceholders.Zip(FormatValues, (name, value) => new KeyValuePair <string, object>(name, value)));
                FormatValues.AddRange(Enumerable.Range(1, FormatPlaceholders.Count - FormatValues.Count).Select(_ => "#MISSING#"));
                return(result);
            }
            else if (FormatPlaceholders.Count == 0)
            {
                return(ParseResult.Error(ValidationErrors.Concat(new[] { "No format placeholders were found" }), Array.Empty <KeyValuePair <string, object> >()));
            }

            return(ParseResult.Create(ValidationErrors.Count == 0, FormatPlaceholders.Zip(FormatValues, (name, value) => new KeyValuePair <string, object>(name, value)), ValidationErrors));
        }
 public void SortPlaceholders()
 {
     FormatPlaceholders = new List <string>(FormatPlaceholders.OrderBy(s => s).ToList());
 }