/// <summary> /// Traverse the given instance /// </summary> /// <param name="instance">The object instance you want to traverse</param> /// <param name="maxDepth">The max depth you find appropriate</param> /// <param name="listener">The listener that will be notified when we find something</param> public virtual void TraverseInstance(object instance, int maxDepth, IInstanceListener listener) { if (!ShouldRecurse(instance.GetType())) { throw new InstanceTraversalException($"{instance.GetType()} is not a type that can be traversed."); } var context = new InstanceTraversalContext { Instance = instance, MaxDepth = maxDepth }; // // constructors // we are doing constructors in the non-recursive part // as we are not interested in constructors of field // and property types // var constructors = instance.GetType().GetTypeInfo().GetConstructors(); foreach (var constructorInfo in constructors) { listener.OnConstructor(constructorInfo, context); } Worker(instance, listener, context); }
/// <summary> /// Traverse the given instance /// </summary> /// <param name="instance">The object instance you want to traverse</param> /// <param name="maxDepth">The max depth you find appropriate</param> /// <param name="listener">The listener that will be notified when we find something</param> public virtual void TraverseInstance(object instance, int maxDepth, IInstanceListener listener) { var context = new InstanceTraversalContext { Instance = instance, MaxDepth = maxDepth }; // // constructors // we are doing constructors in the non-recursive part // as we are not interested in constructors of field // and property types // var constructors = instance.GetType().GetTypeInfo().GetConstructors(); foreach (var constructorInfo in constructors) { listener.OnConstructor(constructorInfo, context); } Worker(instance, listener, context); }