Class PerTypeDispatcher<TBase>
Calls different action delegates based on the runtime types of objects. Types must be exact matches. Inheritance is not considered.
Namespace: NanoByte.Common.Dispatch
Assembly: NanoByte.Common.dll
Syntax
public class PerTypeDispatcher<TBase> : Object where TBase : class
Type Parameters
Name | Description |
---|---|
TBase | The common base type of all objects to be dispatched. |
Constructors
PerTypeDispatcher(Boolean)
Calls different action delegates based on the runtime types of objects. Types must be exact matches. Inheritance is not considered.
Declaration
public PerTypeDispatcher(bool ignoreMissing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | ignoreMissing |
|
Methods
Add<TSpecific>(Action<TSpecific>)
Adds a dispatch delegate.
Declaration
public PerTypeDispatcher<TBase> Add<TSpecific>(Action<TSpecific> action)
where TSpecific : TBase
Parameters
Type | Name | Description |
---|---|---|
Action<TSpecific> | action | The delegate to call. |
Returns
Type | Description |
---|---|
PerTypeDispatcher<TBase> | The "this" pointer for use in a "Fluent API" style. |
Type Parameters
Name | Description |
---|---|
TSpecific | The specific type to call the delegate for. Does not match subtypes |
Dispatch(TBase)
Dispatches an element to the delegate 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. |
Exceptions
Type | Condition |
---|---|
KeyNotFoundException | No delegate matching the |
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. |
Exceptions
Type | Condition |
---|---|
KeyNotFoundException | No delegate matching one of the element types was Add<TSpecific>(Action<TSpecific>)ed. |
GetEnumerator()
Declaration
public IEnumerator<KeyValuePair<Type, Action<object>>> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<KeyValuePair<Type, Action<Object>>> |