Пример #1
0
        public ImmutableList(IEnumerable <T> values, IValueValidator <T> optionalValueValidator)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            Node node = null;

            foreach (var value in values)
            {
                if (optionalValueValidator != null)
                {
                    optionalValueValidator.EnsureValid(value);
                }
                if (node == null)
                {
                    node = new Node(value, null);
                }
                else
                {
                    node = new Node(value, node);
                }
            }
            _tail = node;
            _optionalValueValidator = optionalValueValidator;
            _allValues = null;
        }
Пример #2
0
 /// <summary>
 /// This will throw an exception for a value that does pass validation requirements
 /// </summary>
 public void EnsureValid(T value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     if (_optionalInnerValidator != null)
     {
         _optionalInnerValidator.EnsureValid(value);
     }
 }
        public ImmutableList(IEnumerable <T> values, IValueValidator <T> optionalValueValidator)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            Node node = null;

            foreach (var value in values)
            {
                if (optionalValueValidator != null)
                {
                    optionalValueValidator.EnsureValid(value);
                }
                node = new Node {
                    Value = value, Previous = node, Count = (node?.Count ?? 0) + 1
                };
            }
            _tail = node;
            _optionalValueValidator = optionalValueValidator;
            _allValues = null;
        }