public virtual void VisitEnter(Component component) { var types = new[] {component.GetType()}; MethodInfo methodInfo = GetType().GetMethod("VisitEnter", types); if (methodInfo != null) { methodInfo.Invoke(this, new object[] {component}); } else { throw new Exception("Visitor does not implement the VisitEnter method for the type: " + component.GetType()); } }
public virtual void Visit(Component component) { // Use reflection to find and invoke the correct Visit method var types = new[] {component.GetType()}; MethodInfo methodInfo = GetType().GetMethod("Visit", types); if (methodInfo != null) { methodInfo.Invoke(this, new object[] {component}); } else { throw new Exception("Visitor does not implement the Visit method for the type: " + component.GetType()); } }
public override void Visit(Component component) { if (IsSubclassOfRawGeneric(typeof (WebTestLeaf<>), component.GetType())) { Stack.Push(() => { Context.Logger.NewLine(); Context.Logger.IndentBy++; MethodInfo methodInfo = component.GetType().GetMethod("Execute"); methodInfo.Invoke(component, new object[] { Context }); Context.Logger.IndentBy--; }); } else { throw new NotImplementedException("visitor expects only WebTestLeaf<> types."); } }
public override void VisitLeave(Component component) { if (IsSubclassOfRawGeneric(typeof(WebTestComposite<>), component.GetType())) { Stack.Push(() => { Context.Logger.NewLine(); MethodInfo methodInfo = component.GetType().GetMethod("ExecuteOnLeave"); methodInfo.Invoke(component, new object[] { Context }); Context.Logger.IndentBy--; }); } else { if (component is Sequence) { base.VisitLeave(component); } } }