Esempio n. 1
0
        public void Add(string key, object value)
        {
            if (value == null)
            {
                return;
            }

            if (value is string stringValue)
            {
                StringProperties.Add(key, stringValue);
            }
            else if (value is byte[] binaryValue)
            {
                BinaryProperties.Add(key, binaryValue);
            }
            else if (value is bool boolValue)
            {
                BooleanProperties.Add(key, boolValue);
            }
            else if (value is DateTimeOffset dateTimeOffsetValue)
            {
                DateTimeProperties.Add(key, dateTimeOffsetValue);
            }
            else if (value is DateTime dateTimeValue)
            {
                DateTimeProperties.Add(key, dateTimeValue);
            }
            else
            {
                IntegerProperties.Add(key, Convert.ToInt64(value));
            }
        }
Esempio n. 2
0
        public void Parse(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            Clear();

            // If some search criteria has a space in it, then that criteria should be enclosed in quotes
            // Using this assumption, we find all quoted areas and replace the space(s) temporarily so that we treat it as 1 word
            // This may not be the best solution (definitely not the cleanest), but it should get the job done
            var    processedInput   = new StringBuilder();
            string unprocessedInput = input;

            while (unprocessedInput.Contains(Quote))
            {
                int leftQuoteIndex =
                    unprocessedInput.IndexOf(Quote,
                                             StringComparison.Ordinal); // Guaranteed to be found because we checked with Contains()
                // If the left quote is the last character, then we obviously won't find a right quote
                int rightQuoteIndex = leftQuoteIndex == unprocessedInput.Length - Quote.Length
                    ? -1
                    : unprocessedInput.IndexOf(Quote, leftQuoteIndex + Quote.Length, StringComparison.Ordinal);
                string beforeQuote = unprocessedInput.Substring(0, leftQuoteIndex);
                var    quotation   = string.Empty;
                if (rightQuoteIndex != -1) // If there's no right quote, then we don't have a quotation
                {
                    int startIndex = leftQuoteIndex + Quote.Length;
                    quotation = unprocessedInput.Substring(startIndex, rightQuoteIndex - startIndex)
                                .Replace(Delimiter, Quote);
                }

                processedInput.Append(beforeQuote + quotation);
                // If there's no quotation, we'll finish by taking everything after the 1 quote
                // Otherwise, we'll keep checking the rest of the input for quotations
                unprocessedInput = rightQuoteIndex == -1
                    ? unprocessedInput.Substring(leftQuoteIndex + Quote.Length)
                    : unprocessedInput.Substring(rightQuoteIndex + Quote.Length);
            }

            processedInput.Append(unprocessedInput);
            foreach (string word in processedInput.ToString()
                     .Split(new[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries))
            {
                string token = word.Replace(Quote, Delimiter); // Restore spaces that we temporarily replaced
                if (token.StartsWith(KeywordId))
                {
                    Id = token.Substring(KeywordId.Length);
                }
                else if (token.StartsWith(KeywordSet))
                {
                    SetCode = token.Substring(KeywordSet.Length);
                }
                else if (token.StartsWith(KeywordIs))
                {
                    BoolProperties.Add(token.Substring(KeywordIs.Length), true);
                }
                else if (token.StartsWith(KeywordNot))
                {
                    BoolProperties.Add(token.Substring(KeywordNot.Length), false);
                }
                else if (token.Contains(KeywordString))
                {
                    StringProperties.Add(token.Substring(0, token.IndexOf(KeywordString, StringComparison.Ordinal)),
                                         token.Substring(token.IndexOf(KeywordString, StringComparison.Ordinal) + KeywordString.Length));
                }
                else if (token.Contains(KeywordIntMin) &&
                         int.TryParse(
                             token.Substring(token.IndexOf(KeywordIntMin, StringComparison.Ordinal) +
                                             KeywordIntMin.Length),
                             out int minValue))
                {
                    IntMinProperties.Add(token.Substring(0, token.IndexOf(KeywordIntMin, StringComparison.Ordinal)),
                                         minValue);
                }
                else if (token.Contains(KeywordIntMax) &&
                         int.TryParse(
                             token.Substring(token.IndexOf(KeywordIntMax, StringComparison.Ordinal) +
                                             KeywordIntMax.Length),
                             out int maxValue))
                {
                    IntMaxProperties.Add(token.Substring(0, token.IndexOf(KeywordIntMax, StringComparison.Ordinal)),
                                         maxValue);
                }
                else if (token.Contains(KeywordEnum) &&
                         int.TryParse(
                             token.Substring(token.IndexOf(KeywordEnum, StringComparison.Ordinal) + KeywordEnum.Length),
                             out int enumValue))
                {
                    EnumProperties.Add(token.Substring(0, token.IndexOf(KeywordEnum, StringComparison.Ordinal)),
                                       enumValue);
                }
                else
                {
                    Name += (string.IsNullOrEmpty(Name) ? string.Empty : Delimiter) + token;
                }
            }
        }
 public void AddString(LsName Add)
 {
     StringProperties.Add((BaseProperties.Count + StringProperties.Count), Add);
 }