Class FuncFromMessage<T1, TResult>
A type-dispatching function map that derives a TResult from an
IMessage and one additional argument, routing based on the message's
MessageTypeId.
Inherited Members
Namespace: Unity.SimulationPro.Foundation
Assembly: Unity.SimulationPro.Foundation.dll
Syntax
public class FuncFromMessage<T1, TResult>
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the additional argument passed to every function. |
| TResult | The return type produced by each registered function. |
Methods
Add(MessageTypeId, Func<IMessage, T1, TResult>)
Registers a function for the given MessageTypeId.
Declaration
public void Add(MessageTypeId messageTypeId, Func<IMessage, T1, TResult> callback)
Parameters
| Type | Name | Description |
|---|---|---|
| MessageTypeId | messageTypeId | The message type ID to dispatch on. |
| Func<IMessage, T1, TResult> | callback | The function that produces a result from an IMessage and the additional argument. |
Add<T>(Func<T, T1, TResult>)
Registers a strongly-typed function for messages of type T.
Declaration
public void Add<T>(Func<T, T1, TResult> callback) where T : IMessage
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T, T1, TResult> | callback | The typed function invoked when a message of type |
Type Parameters
| Name | Description |
|---|---|
| T | The concrete IMessage type to handle. |
Invoke(IMessage, T1)
Dispatches the message and additional argument to the registered function and returns the result.
Declaration
public TResult Invoke(IMessage msg, T1 arg1)
Parameters
| Type | Name | Description |
|---|---|---|
| IMessage | msg | The message to dispatch. |
| T1 | arg1 | The additional argument to pass to the function. |
Returns
| Type | Description |
|---|---|
| TResult | The result produced by the registered function. |
Exceptions
| Type | Condition |
|---|---|
| NotImplementedException | Thrown if no function is registered for the message type. |