Class AggregateDispatcher<TBase, TResult>
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).
Namespace: NanoByte.Common.Dispatch
Assembly: NanoByte.Common.dll
Syntax
public class AggregateDispatcher<TBase, TResult> : Object where TBase : class
Type Parameters
Name | Description |
---|---|
TBase | The common base type of all objects to be dispatched. |
TResult | The enumerable return values of the delegates. |
Constructors
AggregateDispatcher()
Declaration
public AggregateDispatcher()
Methods
Add<TSpecific>(Func<TSpecific, IEnumerable<TResult>>)
Adds a dispatch delegate.
Declaration
public AggregateDispatcher<TBase, TResult> Add<TSpecific>(Func<TSpecific, IEnumerable<TResult>> function)
where TSpecific : class, TBase
Parameters
Type | Name | Description |
---|---|---|
Func<TSpecific, IEnumerable<TResult>> | function | The delegate to call. |
Returns
Type | Description |
---|---|
AggregateDispatcher<TBase, TResult> | The "this" pointer for use in a "Fluent API" style. |
Type Parameters
Name | Description |
---|---|
TSpecific | The specific type to call the delegate for. Matches all subtypes as well. |
Dispatch(TBase)
Dispatches an element to all delegates matching the type. Set up with Add<TSpecific>(Func<TSpecific, IEnumerable<TResult>>) first.
Declaration
public IEnumerable<TResult> Dispatch(TBase element)
Parameters
Type | Name | Description |
---|---|---|
TBase | element | The element to be dispatched. |
Returns
Type | Description |
---|---|
IEnumerable<TResult> | The values returned by all matching delegates aggregated. |
Dispatch(IEnumerable<TBase>)
Dispatches for each element in a collection. Set up with Add<TSpecific>(Func<TSpecific, IEnumerable<TResult>>) first.
Declaration
public IEnumerable<TResult> Dispatch(IEnumerable<TBase> elements)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TBase> | elements | The elements to be dispatched. |
Returns
Type | Description |
---|---|
IEnumerable<TResult> | The values returned by the matching delegates. |
GetEnumerator()
Declaration
public IEnumerator<Func<TBase, IEnumerable<TResult>>> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<Func<TBase, IEnumerable<TResult>>> |