1
+ using Common . Exceptions ;
2
+
3
+ namespace Common . Events ;
4
+
5
+ public class Event
6
+ {
7
+ private event EventHandler ? GenericEvent ;
8
+
9
+ public void Invoke ( object sender )
10
+ {
11
+ if ( sender == null )
12
+ {
13
+ throw new CommonException ( "Invalid invocation attempt - sender is null" ) ;
14
+ }
15
+ GenericEvent ? . Invoke ( sender , EventArgs . Empty ) ;
16
+ }
17
+ public void Subscrive ( Action < object > action )
18
+ {
19
+ GenericEvent += ( sender , _ ) => action ( sender ! ) ;
20
+ }
21
+ }
22
+
23
+ public class Event < T >
24
+ where T : class
25
+ {
26
+ private event EventHandler < T > ? GenericEvent ;
27
+
28
+ public void Invoke ( object sender , T data )
29
+ {
30
+ if ( sender == null )
31
+ {
32
+ throw new CommonException ( "Invalid invocation attempt - sender is null" ) ;
33
+ }
34
+ GenericEvent ? . Invoke ( sender , data ) ;
35
+ }
36
+ public void Subscrive ( Action < object , T > action )
37
+ {
38
+ GenericEvent += ( sender , data ) => action ( sender ! , data ) ;
39
+ }
40
+ }
41
+
42
+ public class Event < T1 , T2 >
43
+ where T1 : class
44
+ where T2 : class
45
+ {
46
+ private event EventHandler < ( T1 , T2 ) > ? GenericEvent ;
47
+
48
+ public void Invoke ( object sender , T1 data1 , T2 data2 )
49
+ {
50
+ if ( sender == null )
51
+ {
52
+ throw new CommonException ( "Invalid invocation attempt - sender is null" ) ;
53
+ }
54
+ GenericEvent ? . Invoke ( sender , ( data1 , data2 ) ) ;
55
+ }
56
+ public void Subscrive ( Action < object , T1 , T2 > action )
57
+ {
58
+ GenericEvent += ( sender , data ) => action ( sender ! , data . Item1 , data . Item2 ) ;
59
+ }
60
+ }
0 commit comments