NanoByte.Common  2.6.1
NanoByte.Common.Dispatch.PerTypeDispatcher< TBase, TResult > Class Template Reference

Calls different action delegates based on the runtime types of objects. Types must be exact matches. Inheritance is not considered. More...

Inheritance diagram for NanoByte.Common.Dispatch.PerTypeDispatcher< TBase, TResult >:

Public Member Functions

 PerTypeDispatcher (bool ignoreMissing)
 Creates a new dispatcher. More...
 
PerTypeDispatcher< TBase > Add< TSpecific > (Action< TSpecific > action)
 Adds a dispatch delegate. More...
 
void Dispatch (TBase element)
 Dispatches an element to the delegate matching the type. Set up with Add<TSpecific> first. More...
 
void Dispatch (IEnumerable< TBase > elements)
 Dispatches for each element in a collection. Set up with Add<TSpecific> first. More...
 
IEnumerator< KeyValuePair< Type, Action< object > > > GetEnumerator ()
 
PerTypeDispatcher< TBase, TResult > Add< TSpecific > (Func< TSpecific, TResult > function)
 Adds a dispatch delegate. More...
 
TResult Dispatch (TBase element)
 Dispatches an element to the delegate matching the type. Set up with Add<TSpecific> first. More...
 
IEnumerable< TResult > Dispatch (IEnumerable< TBase > elements)
 Dispatches for each element in a collection. Set up with Add<TSpecific> first. More...
 
IEnumerator< KeyValuePair< Type, Func< TBase, TResult > > > GetEnumerator ()
 

Detailed Description

Calls different action delegates based on the runtime types of objects. Types must be exact matches. Inheritance is not considered.

Calls different function delegates (with return values) based on the runtime types of objects. Types must be exact matches. Inheritance is not considered.

Template Parameters
TBaseThe common base type of all objects to be dispatched.
Template Parameters
TBaseThe common base type of all objects to be dispatched.
TResultThe return value of the delegates.
Type Constraints
TBase :class 

Constructor & Destructor Documentation

◆ PerTypeDispatcher()

NanoByte.Common.Dispatch.PerTypeDispatcher< TBase, TResult >.PerTypeDispatcher ( bool  ignoreMissing)
inline

Creates a new dispatcher.

Parameters
ignoreMissingtrue to silently ignore dispatch attempts on unknown types; false to throw exceptions.

Member Function Documentation

◆ Add< TSpecific >() [1/2]

PerTypeDispatcher<TBase> NanoByte.Common.Dispatch.PerTypeDispatcher< TBase, TResult >.Add< TSpecific > ( Action< TSpecific >  action)
inline

Adds a dispatch delegate.

Template Parameters
TSpecificThe specific type to call the delegate for. Does not match subtypes
Parameters
actionThe delegate to call.
Returns
The "this" pointer for use in a "Fluent API" style.
Type Constraints
TSpecific :TBase 

◆ Add< TSpecific >() [2/2]

PerTypeDispatcher<TBase, TResult> NanoByte.Common.Dispatch.PerTypeDispatcher< TBase, TResult >.Add< TSpecific > ( Func< TSpecific, TResult >  function)
inline

Adds a dispatch delegate.

Template Parameters
TSpecificThe specific type to call the delegate for. Does not match subtypes.
Parameters
functionThe delegate to call.
Returns
The "this" pointer for use in a "Fluent API" style.
Type Constraints
TSpecific :TBase 

◆ Dispatch() [1/4]

void NanoByte.Common.Dispatch.PerTypeDispatcher< TBase, TResult >.Dispatch ( IEnumerable< TBase >  elements)
inline

Dispatches for each element in a collection. Set up with Add<TSpecific> first.

Parameters
elementsThe elements to be dispatched.
Exceptions
KeyNotFoundExceptionNo delegate matching one of the element types was Add<TSpecific>ed and _ignoreMissing is false.

◆ Dispatch() [2/4]

IEnumerable<TResult> NanoByte.Common.Dispatch.PerTypeDispatcher< TBase, TResult >.Dispatch ( IEnumerable< TBase >  elements)
inline

Dispatches for each element in a collection. Set up with Add<TSpecific> first.

Parameters
elementsThe elements to be dispatched.
Returns
The values returned by the matching delegates.
Exceptions
KeyNotFoundExceptionNo delegate matching one of the element types was Add<TSpecific>ed.

◆ Dispatch() [3/4]

void NanoByte.Common.Dispatch.PerTypeDispatcher< TBase, TResult >.Dispatch ( TBase  element)
inline

Dispatches an element to the delegate matching the type. Set up with Add<TSpecific> first.

Parameters
elementThe element to be dispatched.
Exceptions
KeyNotFoundExceptionNo delegate matching the element type was Add<TSpecific>ed and _ignoreMissing is false.

◆ Dispatch() [4/4]

TResult NanoByte.Common.Dispatch.PerTypeDispatcher< TBase, TResult >.Dispatch ( TBase  element)
inline

Dispatches an element to the delegate matching the type. Set up with Add<TSpecific> first.

Parameters
elementThe element to be dispatched.
Returns
The value returned by the matching delegate.
Exceptions
KeyNotFoundExceptionNo delegate matching the element type was Add<TSpecific>ed.

The documentation for this class was generated from the following files: