File tree 2 files changed +47
-0
lines changed
EssentialCSharp/Chapter13
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ namespace AddisonWesley . Michaelis . EssentialCSharp . Chapter13 . Listing13_17
2
+ {
3
+ using System ;
4
+
5
+ public class Thermostat
6
+ {
7
+ // ...
8
+ // Declaring the delegate field to save the
9
+ // list of subscribers.
10
+ private EventHandler < TemperatureArgs > _OnTemperatureChange ;
11
+
12
+ public void add_OnTemperatureChange (
13
+ EventHandler < TemperatureArgs > handler )
14
+ {
15
+ System . Delegate . Combine ( _OnTemperatureChange , handler ) ;
16
+ }
17
+
18
+ public void remove_OnTemperatureChange (
19
+ EventHandler < TemperatureArgs > handler )
20
+ {
21
+ System . Delegate . Remove ( _OnTemperatureChange , handler ) ;
22
+ }
23
+
24
+ //public event EventHandler<TemperatureArgs> OnTemperatureChange
25
+ //{
26
+ // //Would cause a compiler error.
27
+ // add
28
+ // {
29
+ // add_OnTemperatureChange(value);
30
+ // }
31
+ // //Would cause a compiler error.
32
+ // remove
33
+ // {
34
+ // remove_OnTemperatureChange(value);
35
+ // }
36
+ //}
37
+
38
+ public class TemperatureArgs : System . EventArgs
39
+ {
40
+ public TemperatureArgs ( float newTemperature )
41
+ {
42
+ }
43
+
44
+ }
45
+ }
46
+ }
Original file line number Diff line number Diff line change 70
70
<Compile Include =" Listing13.04.InvokingADelegate.cs" />
71
71
<Compile Include =" Listing13.13.DeclaringAGenericDelegateType.cs" />
72
72
<Compile Include =" Listing13.16.DeclaringTheOnTemperatureChangeEvent.cs" />
73
+ <Compile Include =" Listing13.17.CSharpConceptualEquivalentOfEventCILCode.cs" />
73
74
<Compile Include =" Listing13.18.CustomAddAndRemoveHandlers.cs" />
74
75
<Compile Include =" Listing13.15.UsingCustomDelegateType.cs" />
75
76
<Compile Include =" Listing13.14.FiringTheEventNotification.cs" />
You can’t perform that action at this time.
0 commit comments