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