Class VisitorPatternHelper<ReturnType>
Helper class for performing a Visitor-type invocation of methods on some node structure
Namespace: SuperOffice.Util
Assembly: SoCore.dll
Syntax
public sealed class VisitorPatternHelper<ReturnType> : Object
Type Parameters
Name | Description |
---|---|
ReturnType | Return type for the visit methods |
Remarks
See http://en.wikipedia.org/wiki/Visitor_pattern for a description of the Visitor pattern. Visitor is a fairly abstract pattern and will usually require some thought to follow through.
TheConstructors
VisitorPatternHelper(String, Object)
Initialize the visitor helper with a method prefix and a target class
Declaration
public VisitorPatternHelper(string methodPrefix, object targetClass)
Parameters
Type | Name | Description |
---|---|---|
String | methodPrefix | The prefix that all visitation methods must be named with |
Object | targetClass | The class that contains the visitation methods |
Remarks
See http://en.wikipedia.org/wiki/Visitor_pattern for a description of the Visitor pattern. Visitor is a fairly abstract pattern and will usually require some thought to follow through.
TheMethods
InvokeStrictVisitor(Object[])
Invoke the visitor, by finding and calling the method in the target class that has a signature matching the visitorArguments. If no such method is found, an exception is thrown.
Declaration
public ReturnType InvokeStrictVisitor(params object[] visitorArguments)
Parameters
Type | Name | Description |
---|---|---|
Object[] | visitorArguments | Arguments to the method to be called |
Returns
Type | Description |
---|---|
ReturnType | Return value from the visitation method |
Remarks
See http://en.wikipedia.org/wiki/Visitor_pattern for a description of the Visitor pattern. Visitor is a fairly abstract pattern and will usually require some thought to follow through.
TheExceptions
Type | Condition |
---|---|
SoNotImplementedException | Thrown if the target class (given to the constructor) does not contain a method with the given name prefix and parameter signature corresponding to the current set of parameters (visitorArguments) |
InvokeTolerantVisitor(Object[])
Invoke the visitor, by finding and calling the method in the target class that has a signature matching the visitorArguments. If no such method is found, no call is made and default(ReturnType) is returned (no exception thrown).
Declaration
public ReturnType InvokeTolerantVisitor(params object[] visitorArguments)
Parameters
Type | Name | Description |
---|---|---|
Object[] | visitorArguments | Arguments to the method to be called |
Returns
Type | Description |
---|---|
ReturnType | Return value from the visitation method |
Remarks
See http://en.wikipedia.org/wiki/Visitor_pattern for a description of the Visitor pattern. Visitor is a fairly abstract pattern and will usually require some thought to follow through.
TheInvokeVisitor(Boolean, Object[])
InvokeVisitor checks the in-parameters type against the already existing method dictionary. When the key is found in the array, the key's object method is called.
Declaration
public ReturnType InvokeVisitor(bool failIfMissing, params object[] visitorArguments)
Parameters
Type | Name | Description |
---|---|---|
Boolean | failIfMissing | |
Object[] | visitorArguments | arguments as passed to the method. The arguments' type needs to be an exact match of the type implemented in the appropriate target method. |
Returns
Type | Description |
---|---|
ReturnType | returns the ReturnType returned from the Invoked target method |
Remarks
See http://en.wikipedia.org/wiki/Visitor_pattern for a description of the Visitor pattern. Visitor is a fairly abstract pattern and will usually require some thought to follow through.
TheExceptions
Type | Condition |
---|---|
SoNotImplementedException | There is no appropriate method to invoke. |
SoException | An exception was thrown while trying to invoke the target method |