Пример #1
0
        public static bool TryParse(string str, out IntegerRange range)
        {
            var end = 0;

            while (end < str.Length && char.IsDigit(str, end))
            {
                end += 1;
            }
            if (end > 0)
            {
                if (end == str.Length)
                {
                    if (int.TryParse(str, out var minmax))
                    {
                        range = new IntegerRange(minmax);
                        return(true);
                    }
                }
                else if (str[end] == '-' && int.TryParse(str.Substring(0, end), out var min))
                {
                    var start = end = end + 1;
                    while (end < str.Length && char.IsDigit(str, end))
                    {
                        end += 1;
                    }
                    if (end > start && end == str.Length)
                    {
                        if (int.TryParse(str.Substring(start, end - start), out var max))
                        {
                            range = new IntegerRange(min, max);
                            return(true);
                        }
                    }
                }
            }

            range = default;
            return(false);
        }
Пример #2
0
 public bool Overlaps(IntegerRange other)
 {
     return(Contains(other.Min) || Contains(other.Max) || other.Contains(Min) || other.Contains(Max));
 }