Esempio n. 1
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. 2
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);
                }
            }
        }