Show / Hide Table of Contents

Class VisitorPatternHelper<ReturnType>

Helper class for performing a Visitor-type invocation of methods on some node structure

Inheritance
object
VisitorPatternHelper<ReturnType>
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
Namespace: SuperOffice.Util
Assembly: SoCore.dll
Syntax
public sealed class VisitorPatternHelper<ReturnType>
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.

The VisitorPatternHelper class performs the dispatching/invocation of visitor methods, so the client class only needs to provide methods that handle the required types of nodes in the visited structure.

Generally the client class will provide a class instance that contains one or more Visit methods. It will then call the InvokeStrictVisitor(params object[]) or InvokeTolerantVisitor(params object[]) method, giving the root node of some structure to be visited as the input parameter(s).

The VisitorPatternHelper will reflect on the client class and try to find a method whose signature matches the input. If it finds one, it will forward the call to this method, which may recursively call one of the InvokeXXXVisitor methods in turn.

Constructors

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.

The VisitorPatternHelper class performs the dispatching/invocation of visitor methods, so the client class only needs to provide methods that handle the required types of nodes in the visited structure.

Generally the client class will provide a class instance that contains one or more Visit methods. It will then call the InvokeStrictVisitor(params object[]) or InvokeTolerantVisitor(params object[]) method, giving the root node of some structure to be visited as the input parameter(s).

The VisitorPatternHelper will reflect on the client class and try to find a method whose signature matches the input. If it finds one, it will forward the call to this method, which may recursively call one of the InvokeXXXVisitor methods in turn.

Methods

InvokeStrictVisitor(params 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.

The VisitorPatternHelper class performs the dispatching/invocation of visitor methods, so the client class only needs to provide methods that handle the required types of nodes in the visited structure.

Generally the client class will provide a class instance that contains one or more Visit methods. It will then call the InvokeStrictVisitor(params object[]) or InvokeTolerantVisitor(params object[]) method, giving the root node of some structure to be visited as the input parameter(s).

The VisitorPatternHelper will reflect on the client class and try to find a method whose signature matches the input. If it finds one, it will forward the call to this method, which may recursively call one of the InvokeXXXVisitor methods in turn.
Exceptions
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(params 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.

The VisitorPatternHelper class performs the dispatching/invocation of visitor methods, so the client class only needs to provide methods that handle the required types of nodes in the visited structure.

Generally the client class will provide a class instance that contains one or more Visit methods. It will then call the InvokeStrictVisitor(params object[]) or InvokeTolerantVisitor(params object[]) method, giving the root node of some structure to be visited as the input parameter(s).

The VisitorPatternHelper will reflect on the client class and try to find a method whose signature matches the input. If it finds one, it will forward the call to this method, which may recursively call one of the InvokeXXXVisitor methods in turn.

InvokeVisitor(bool, params 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
bool 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.

The VisitorPatternHelper class performs the dispatching/invocation of visitor methods, so the client class only needs to provide methods that handle the required types of nodes in the visited structure.

Generally the client class will provide a class instance that contains one or more Visit methods. It will then call the InvokeStrictVisitor(params object[]) or InvokeTolerantVisitor(params object[]) method, giving the root node of some structure to be visited as the input parameter(s).

The VisitorPatternHelper will reflect on the client class and try to find a method whose signature matches the input. If it finds one, it will forward the call to this method, which may recursively call one of the InvokeXXXVisitor methods in turn.
Exceptions
Type Condition
SoNotImplementedException

There is no appropriate method to invoke.

SoException

An exception was thrown while trying to invoke the target method

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top