示例#1
0
 /// <summary>
 /// Пересечение двух диапазонов.
 /// </summary>
 public NumberRange Intersect
 (
     NumberRange other
 )
 {
     return(new NumberRange
            (
                Stop,
                other.Start
            ));
 }
示例#2
0
 /// <summary>
 /// Объединение двух диапазонов.
 /// </summary>
 public NumberRange Union
 (
     NumberRange other
 )
 {
     return(new NumberRange
            (
                NumberText.Min(Start, other.Start),
                NumberText.Max(Stop, other.Stop)
            ));
 }
 /// <summary>
 /// Добавление диапазона в набор.
 /// </summary>
 /// <param name="range"></param>
 /// <returns></returns>
 public NumberRangeCollection Add
 (
     NumberRange range
 )
 {
     if (ReferenceEquals(range, null))
     {
         throw new ArgumentNullException("range");
     }
     _items.Add(range);
     return(this);
 }
 private NumberRangeCollection
 (
     NumberRangesParser.ProgramContext program
 )
     : this()
 {
     foreach (NumberRangesParser.ItemContext itemContext
              in program.item())
     {
         NumberRange range = new NumberRange(itemContext);
         _items.Add(range);
     }
 }
示例#5
0
        /// <summary>
        /// Разбор текстового представления диапазона.
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static NumberRange Parse
        (
            string text
        )
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("text");
            }
            text = text.Trim();
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("text");
            }

            NumberRange result;

            if (text.Contains("-"))
            {
                string[] parts = text.Split('-');
                if (parts.Length != 2)
                {
                    throw new FormatException("text");
                }
                parts[0] = parts[0].Trim();
                parts[1] = parts[1].Trim();
                if (string.IsNullOrEmpty(parts[0]) ||
                    string.IsNullOrEmpty(parts[1]))
                {
                    throw new FormatException("text");
                }
                result = new NumberRange
                         (
                    parts[0],
                    parts[1]
                         );
            }
            else
            {
                result = new NumberRange(text);
            }
            return(result);
        }