Beispiel #1
0
        public bool Check(Data data)
        {
            var firstArgument = _firstArgumentSelector.SelectData(data);
            var secondArgument = _secondArgumentSelector.SelectData(data);

            IComparer comparer = new Comparer(CultureInfo.CurrentCulture);
            int compareResult = comparer.Compare(firstArgument, secondArgument);
            return _checkComparisonResult(compareResult);
        }
Beispiel #2
0
        public object ExtractSingleValue(Data root, IEnumerable<string> path)
        {
            Contract.Requires(root != null);
            Contract.Requires(path != null);

            var currentNode = root;
            foreach (var pathElement in path)
            {
                if (!(currentNode is DataNode))
                    return DataNotFound.Instance;
                var node = (DataNode) currentNode;
                var selectedNodes = node.Children.Where(c => Equals(c.Name, pathElement));
                if (selectedNodes.Count() > 1)
                    throw new Exception("Data is ambiguous");
                if (!selectedNodes.Any())
                    return DataNotFound.Instance;
                currentNode = selectedNodes.Single();
            }
            if (currentNode is DataAttribute) return ((DataAttribute) currentNode).GetValue();
            return currentNode;
        }