-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubject.cs
51 lines (44 loc) · 1.36 KB
/
Subject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Text;
namespace DelegatesLambdasEvents
{
public class Subject
{
public string Name { get; set; }
private Action triggerListeners;
public event EventHandler TriggerListenersByEventHandler;
public event EventHandler<CustomizedEventArgs> EventHandlerWithEventArgs;
public event Action TriggerListeners
{
add
{
triggerListeners += value;
Console.WriteLine("Aciton was added");
}
remove
{
triggerListeners -= value;
Console.WriteLine("Action was removed");
}
}
public void CalEventHandlerWithEventArgs()
{
Volume vol = new Random().Next() % 2 == 0 ? Volume.Loud : Volume.Louder;
if (EventHandlerWithEventArgs != null)
{
EventHandlerWithEventArgs(this, new CustomizedEventArgs(vol));
}
}
public void BeTippedOver()
{
if (TriggerListenersByEventHandler != null)
TriggerListenersByEventHandler(this, EventArgs.Empty);
}
public void InvokeAction()
{
if (triggerListeners != null)
triggerListeners();
}
}
}