Status:
Framework to develop modular extendable visitors
With NVisitor, you
- Define visitors for a class family without renouncing to extend the family itself
- Can pause the visit to process the intermediate result
- Implement visitors without instrumentalizing the visited class family
NVisitor is entirely type-safe even if it performs lookup by reflection to perform visitor dispatching.
See the initial problem solved by NVisitor: nvisitor-released.
NVisitor is at the core of the test case generator NCase.
Name | Visit Signature |
---|---|
ActionVisitor | void Visit(Node node) |
ActionPayloadVisitor | void Visit(Node node, TPayload payload) |
FuncVisitor | TResult Visit(Node node) |
FuncPayloadVisitor | TResult Visit(Node node, TPayload payload) |
ActionPairVisitor | void Visit(Car c, Driver d) |
ActionPairPayloadVisitor | void Visit(Car c, Driver d, TPayload payload) |
FuncPairVisitor | TResult Visit(Car c, Driver d) |
FuncPayloadPairVisitor | TResult Visit(Car c, Driver d, TPayload payload) |
LazyVisitor | IEnumerable<Pause> Visit(Node node) |
Install package : https://www.nuget.org/packages/NVisitor.
- Clone locally this github repository
- Build the
NVisitor.sln
solution
See demo-unit-tests:
-
Action visitor: http://github.com/jeromerg/NVisitor/blob/master/src/NVisitorTest/Api/Demo/ActionVisitorDemo.cs
-
Lazy visitor: http://github.com/jeromerg/NVisitor/blob/master/src/NVisitorTest/Api/Demo/LazyVisitorDemo.cs
The core of NVisitor is the VisitFactory
, which resolves the visitor, creates the visit-delegates and caches them. It has been developed with focus on extendability and re-usability. You can easily re-use it to implement alternative visitors, i.e. passing arguments or returning collections...