示例#1
0
        public void Validate(Expression <Func <T, bool> > predicate)
        {
            if (!predicate.Compile(true).Invoke(item))
            {
                var memberValues = ExpressionDumper <T> .DumpMemberValues(item, predicate);

                var message = string.Format($"{predicate.ToThisBodyString()}, {memberValues}, {BuildPkMessage()}");
                resultSet.AddFail(typeof(T), "Validate failed: " + message, item);
            }
        }
示例#2
0
        public void Unique <TProperty>(Expression <Func <TElement, TProperty> > selector, IEqualityComparer <TProperty> equalityComparer)
        {
            var f = selector.Compile(true);

            var set = new HashSet <TProperty>(equalityComparer);

            foreach (var item in tableData)
            {
                var v = f(item);
                if (!set.Add(v))
                {
                    resultSet.AddFail(typeof(TElement), "Unique failed:" + selector.ToSpaceBodyString() + ", value = " + v + ", " + BuildPkMessage(item), item);
                }
            }
        }
示例#3
0
        public void Exists <TProperty>(Expression <Func <TElement, TProperty> > elementSelector, Expression <Func <TReference, TProperty> > referenceElementSelector, EqualityComparer <TProperty> equalityComparer)
        {
            var f1 = elementSelector.Compile(true);
            var f2 = referenceElementSelector.Compile(true);

            var compareBase = f1(item);

            foreach (var refItem in referenceTable)
            {
                if (equalityComparer.Equals(compareBase, f2(refItem)))
                {
                    return;
                }
            }

            // not found, assert.
            var from = elementSelector.ToNameBodyString(typeof(TElement).Name);
            var to   = referenceElementSelector.ToNameBodyString(typeof(TReference).Name);

            resultSet.AddFail(typeof(TElement), "Exists failed: " + from + " -> " + to + ", value = " + compareBase + ", " + BuildPkMessage(), item);
        }