Table of Contents

Class AggregateDispatcher<TBase, TResult>

Namespace
NanoByte.Common.Dispatch
Assembly
NanoByte.Common.dll

Calls different function delegates (with enumerable return values) based on the runtime types of objects. Aggregates results when multiple delegates match a type (through inheritance).

public class AggregateDispatcher<TBase, TResult> where TBase : class

Type Parameters

TBase

The common base type of all objects to be dispatched.

TResult

The enumerable return values of the delegates.

Inheritance
object
AggregateDispatcher<TBase, TResult>
Extension Methods

Methods

Add<TSpecific>(Func<TSpecific, IEnumerable<TResult>>)

Adds a dispatch delegate.

public AggregateDispatcher<TBase, TResult> Add<TSpecific>(Func<TSpecific, IEnumerable<TResult>> function) where TSpecific : class, TBase

Parameters

function Func<TSpecific, IEnumerable<TResult>>

The delegate to call.

Returns

AggregateDispatcher<TBase, TResult>

The "this" pointer for use in a "Fluent API" style.

Type Parameters

TSpecific

The specific type to call the delegate for. Matches all subtypes as well.

Dispatch(IEnumerable<TBase>)

Dispatches for each element in a collection. Set up with Add<TSpecific>(Func<TSpecific, IEnumerable<TResult>>) first.

public IEnumerable<TResult> Dispatch(IEnumerable<TBase> elements)

Parameters

elements IEnumerable<TBase>

The elements to be dispatched.

Returns

IEnumerable<TResult>

The values returned by the matching delegates.

Dispatch(TBase)

Dispatches an element to all delegates matching the type. Set up with Add<TSpecific>(Func<TSpecific, IEnumerable<TResult>>) first.

public IEnumerable<TResult> Dispatch(TBase element)

Parameters

element TBase

The element to be dispatched.

Returns

IEnumerable<TResult>

The values returned by all matching delegates aggregated.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<Func<TBase, IEnumerable<TResult>>> GetEnumerator()

Returns

IEnumerator<Func<TBase, IEnumerable<TResult>>>

An enumerator that can be used to iterate through the collection.