Microscopic Traffic Simulator

- Main Page
- Packages
- Classes
- Files

- File List

ParameterizedMessage.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3
4 namespace Microscopic_Traffic_Simulator.ViewModels.Messages
5 {
9 abstract class ParameterizedMessage<TPayload> : MessageBase
10 {
14 private HashSet<Action<TPayload>> subscribers = new HashSet<Action<TPayload>>();
15
21 internal void Subscribe(Action<TPayload> subscriber)
22 {
23 subscribers.Add(subscriber);
24 }
25
31 internal void Unsubcsribe(Action<TPayload> subscriber)
32 {
33 subscribers.Remove(subscriber);
34 }
35
39 internal void Publish(TPayload payload)
40 {
41 foreach (Action<TPayload> subscriber in subscribers)
42 {
43 subscriber(payload);
44 }
45 }
46 }
47
51 abstract class ParameterizedMessage<TPayload, TPayload2> : MessageBase
52 {
56 private HashSet<Action<TPayload, TPayload2>> subscribers = new HashSet<Action<TPayload, TPayload2>>();
57
63 internal void Subscribe(Action<TPayload, TPayload2> subscriber)
64 {
65 subscribers.Add(subscriber);
66 }
67
73 internal void Unsubcsribe(Action<TPayload, TPayload2> subscriber)
74 {
75 subscribers.Remove(subscriber);
76 }
77
81 internal void Publish(TPayload payload, TPayload2 payload2)
82 {
83 foreach (Action<TPayload, TPayload2> subscriber in subscribers)
84 {
85 subscriber(payload, payload2);
86 }
87 }
88 }
89 }
System
Microscopic_Traffic_Simulator.ViewModels.Messages.ParameterizedMessage
Class representing message with payload.
Definition: ParameterizedMessage.cs:9
Microscopic_Traffic_Simulator.ViewModels.Messages.MessageBase
Base class for message to be used by messenger.
Definition: MessageBase.cs:7
Microscopic_Traffic_Simulator
Definition: App.xaml.cs:12