Class AggregateDispatcher<TBase>
Calls different action delegates based on the runtime types of objects. Calls multiple delegates when they all match a type (through inheritance).
Namespace: NanoByte.Common.Dispatch
Assembly: NanoByte.Common.dll
Syntax
public class AggregateDispatcher<TBase> : Object where TBase : class
Type Parameters
Name | Description |
---|---|
TBase | The common base type of all objects to be dispatched. |
Constructors
AggregateDispatcher()
Declaration
public AggregateDispatcher()
Methods
Add<TSpecific>(Action<TSpecific>)
Adds a dispatch delegate.
Declaration
public AggregateDispatcher<TBase> Add<TSpecific>(Action<TSpecific> action)
where TSpecific : class, TBase
Parameters
Type | Name | Description |
---|---|---|
Action<TSpecific> | action | The delegate to call. |
Returns
Type | Description |
---|---|
AggregateDispatcher<TBase> | 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>(Action<TSpecific>) first.
Declaration
public void Dispatch(TBase element)
Parameters
Type | Name | Description |
---|---|---|
TBase | element | The element to be dispatched. |
Dispatch(IEnumerable<TBase>)
Dispatches for each element in a collection. Set up with Add<TSpecific>(Action<TSpecific>) first.
Declaration
public void Dispatch(IEnumerable<TBase> elements)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TBase> | elements | The elements to be dispatched. |
GetEnumerator()
Declaration
public IEnumerator<Action<TBase>> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<Action<TBase>> |