Esempio n. 1
0
        private ReflectionWrapper FindMember(ReflectionWrapper other)
        {
            var fields = this.GetSubExtendedMemberInfosFields();

            foreach (var info in fields)
            {
                if (other.NameInSource == info.NameInSource)
                {
                    return(info);
                }
            }

            return(null);
        }
Esempio n. 2
0
        private void MapFields(
            ReflectionWrapper expected,
            ICollection <object> scanned,
            int depth, Func <ReflectionWrapper, ReflectionWrapper, int, bool> mapFunction)
        {
            if (!mapFunction(this, expected, depth))
            {
                // no need to recurse
                return;
            }

            if (this.Value != null)
            {
                // logic recursion prevention, only for (non null) reference type
                if (scanned.Contains(this.Value))
                {
                    return;
                }

                scanned.Add(this.Value);
            }

            // we recurse
            var nextDepth = depth - 1;

            foreach (var member in this.GetSubExtendedMemberInfosFields())
            {
                member.MapFields(expected.FindMember(member), scanned, nextDepth, mapFunction);
            }

            // we deal with missing fields (unless asked to ignore them)
            if (this.Criteria.IgnoreExtra)
            {
                return;
            }

            foreach (var expectedField in expected.GetSubExtendedMemberInfosFields())
            {
                if (this.FindMember(expectedField) == null)
                {
                    mapFunction(null, expectedField, nextDepth);
                }
            }
        }
Esempio n. 3
0
        private static AggregatedDifference AnonymousTypeDifference <TA, TE>(TA actual, TE expected, Type type,
                                                                             AggregatedDifference result)
        {
            var criteria = new ClassMemberCriteria(BindingFlags.Instance);

            criteria.SetPublic();
            criteria.CaptureProperties();
            criteria.CaptureFields();
            // use field based comparison
            var wrapper       = ReflectionWrapper.BuildFromInstance(type, expected, criteria);
            var actualWrapped = ReflectionWrapper.BuildFromInstance(actual.GetType(), actual, criteria);

            foreach (var match in actualWrapped.MemberMatches(wrapper).Where(match => !match.DoValuesMatches))
            {
                result.Add(DifferenceDetails.FromMatch(match));
            }

            return(result);
        }
Esempio n. 4
0
        private void MapFields(
            ReflectionWrapper actual,
            ICollection <object> scanned,
            int depth, Func <ReflectionWrapper, ReflectionWrapper, int, bool> mapFunction)
        {
            if (this.ValueType.IsClass() && this.Value != null)
            {
                // logic recursion prevention, only for (non null) reference type
                if (scanned.Contains(this.Value))
                {
                    return;
                }

                scanned.Add(this.Value);
            }

            if (!mapFunction(this, actual, depth))
            {
                // no need to recurse
                return;
            }

            // we recurse
            foreach (var member in this.GetSubExtendedMemberInfosFields())
            {
                member.MapFields(actual.FindMember(member), scanned, depth - 1, mapFunction);
            }

            // we deal with missing fields
            if (this.Criteria.IgnoreExtra)
            {
                return;
            }

            foreach (var actualFields in actual.GetSubExtendedMemberInfosFields())
            {
                if (this.FindMember(actualFields) == null)
                {
                    mapFunction(null, actualFields, depth - 1);
                }
            }
        }
Esempio n. 5
0
        internal List <MemberMatch> MemberMatches <TU>(TU expectedValue)
        {
            var expectedWrapped =
                ReflectionWrapper.BuildFromInstance(expectedValue?.GetType() ?? typeof(TU), expectedValue, this.Criteria);

            var result = new List <MemberMatch>();

            expectedWrapped.MapFields(this, 1, (expected, actual, depth) =>
            {
                if (actual?.Value == null || expected?.Value == null)
                {
                    result.Add(new MemberMatch(expected, actual));
                    return(false);
                }

                if (depth <= 0 && expected.ValueType.ImplementsEquals())
                {
                    result.Add(new MemberMatch(expected, actual));
                    return(false);
                }

                if (!expected.IsArray)
                {
                    return(true);
                }

                if (actual.IsArray && ((Array)expected.Value).Length == ((Array)actual.Value).Length)
                {
                    return(true);
                }

                result.Add(new MemberMatch(expected, actual));
                return(false);
            });
            return(result);
        }
Esempio n. 6
0
        private ReflectionWrapper FindMember(ReflectionWrapper other)
        {
            var fields = this.GetSubExtendedMemberInfosFields();

            return(fields.FirstOrDefault(info => other.NameInSource == info.NameInSource));
        }
Esempio n. 7
0
 internal void MapFields(ReflectionWrapper other,
                         int depth, Func <ReflectionWrapper, ReflectionWrapper, int, bool> mapFunction)
 {
     this.MapFields(other, new List <object>(), depth, mapFunction);
 }
Esempio n. 8
0
 public MemberMatch(ReflectionWrapper expected, ReflectionWrapper actual)
 {
     this.Actual   = actual;
     this.Expected = expected;
 }