Example #1
0
        private void VisitInternal(System.Collections.Generic.Stack <TypeVisit> stack, System.Collections.Generic.ISet <Type> visitedSet)
        {
            var type = stack.CurrentType();

            if (configuration.AvoidMultipleVisits && visitedSet.Contains(type))
            {
                return;
            }
            else
            {
                visitedSet.Add(type);
            }

            if (!configuration.TypeCanBeVisited(type))
            {
                return;
            }

            Action(stack);

            if (configuration.VisitInheritedTypes)
            {
                foreach (var(inheritedType, stackEntry) in type.GetInheritedTypes())
                {
                    VisitInternalWithStackWrapping(inheritedType, stack, visitedSet, stackEntry);
                }
            }

            if (configuration.VisitEncompassingTypes)
            {
                foreach (var(encompassingType, stackEntry) in type.GetEncompassingTypes())
                {
                    VisitInternalWithStackWrapping(encompassingType, stack, visitedSet, stackEntry);
                }
            }


            if (configuration.VisitAssignableTypesOf(type))
            {
                var assignableTypes = type.GetAssignableTypes(AppDomain.CurrentDomain);
                foreach (var(assignableType, stackEntry) in assignableTypes)
                {
                    VisitInternalWithStackWrapping(assignableType, stack, visitedSet, stackEntry);
                }
            }

            foreach (var(propertyType, stackEntry) in
                     type
                     .GetProperties()
                     .Where(x => configuration.PropertyCanBeVisited(x))
                     .Select(x => (type: x.PropertyType, stackEntry: (TypeVisit) new PropertyTypeVisit(x.PropertyType, x.Name)))
                     )
            {
                VisitInternalWithStackWrapping(propertyType, stack, visitedSet, stackEntry);
            }
        }