1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Diagnostics;
|
---|
6 | using System.ComponentModel;
|
---|
7 | using System.Collections.Specialized;
|
---|
8 | using System.Windows;
|
---|
9 | using Microsoft.Research.DynamicDataDisplay.Common;
|
---|
10 |
|
---|
11 | namespace Microsoft.Research.DynamicDataDisplay
|
---|
12 | {
|
---|
13 | public static class EventExtensions
|
---|
14 | {
|
---|
15 | [DebuggerStepThrough]
|
---|
16 | [DebuggerHidden]
|
---|
17 | public static void Raise<T>(this EventHandler<T> @event, object sender, T args) where T : EventArgs
|
---|
18 | {
|
---|
19 | if (@event != null)
|
---|
20 | {
|
---|
21 | @event(sender, args);
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | [DebuggerStepThrough]
|
---|
26 | [DebuggerHidden]
|
---|
27 | public static void Raise(this EventHandler @event, object sender)
|
---|
28 | {
|
---|
29 | if (@event != null)
|
---|
30 | {
|
---|
31 | @event(sender, EventArgs.Empty);
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | [DebuggerStepThrough]
|
---|
36 | [DebuggerHidden]
|
---|
37 | public static void Raise(this EventHandler @event, object sender, EventArgs args)
|
---|
38 | {
|
---|
39 | if (@event != null)
|
---|
40 | {
|
---|
41 | @event(sender, args);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | [DebuggerStepThrough]
|
---|
46 | [DebuggerHidden]
|
---|
47 | public static void Raise(this PropertyChangedEventHandler @event, object sender, string propertyName)
|
---|
48 | {
|
---|
49 | if (@event != null)
|
---|
50 | {
|
---|
51 | @event(sender, new PropertyChangedEventArgs(propertyName));
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | /// <summary>
|
---|
56 | /// Raises the specified event with Reset action.
|
---|
57 | /// </summary>
|
---|
58 | /// <param name="event">The event.</param>
|
---|
59 | /// <param name="sender">The sender.</param>
|
---|
60 | [DebuggerStepThrough]
|
---|
61 | [DebuggerHidden]
|
---|
62 | public static void Raise(this NotifyCollectionChangedEventHandler @event, object sender)
|
---|
63 | {
|
---|
64 | if (@event != null)
|
---|
65 | {
|
---|
66 | @event(sender, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | [DebuggerStepThrough]
|
---|
71 | [DebuggerHidden]
|
---|
72 | public static void Raise(this NotifyCollectionChangedEventHandler @event, object sender, NotifyCollectionChangedAction action)
|
---|
73 | {
|
---|
74 | if (@event != null)
|
---|
75 | {
|
---|
76 | @event(sender, new NotifyCollectionChangedEventArgs(action));
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | [DebuggerStepThrough]
|
---|
81 | [DebuggerHidden]
|
---|
82 | public static void Raise(this NotifyCollectionChangedEventHandler @event, object sender, NotifyCollectionChangedEventArgs e)
|
---|
83 | {
|
---|
84 | if (e == null)
|
---|
85 | throw new ArgumentNullException("e");
|
---|
86 |
|
---|
87 | if (@event != null)
|
---|
88 | {
|
---|
89 | @event(sender, e);
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | [DebuggerStepThrough]
|
---|
94 | [DebuggerHidden]
|
---|
95 | public static void RaiseRoutedEvent(this UIElement sender, RoutedEvent routedEvent)
|
---|
96 | {
|
---|
97 | sender.RaiseEvent(new RoutedEventArgs(routedEvent));
|
---|
98 | }
|
---|
99 |
|
---|
100 | /// <summary>
|
---|
101 | /// Raises the specified value changed event.
|
---|
102 | /// </summary>
|
---|
103 | /// <typeparam name="T"></typeparam>
|
---|
104 | /// <typeparam name="TValue">The type of the value.</typeparam>
|
---|
105 | /// <param name="event">The event.</param>
|
---|
106 | /// <param name="sender">The sender of event.</param>
|
---|
107 | /// <param name="prevValue">The previous value.</param>
|
---|
108 | /// <param name="currValue">The current value.</param>
|
---|
109 | [DebuggerStepThrough]
|
---|
110 | [DebuggerHidden]
|
---|
111 | public static void Raise<TValue>(this EventHandler<ValueChangedEventArgs<TValue>> @event, object sender, TValue prevValue, TValue currValue)
|
---|
112 | {
|
---|
113 | if (@event != null)
|
---|
114 | {
|
---|
115 | ValueChangedEventArgs<TValue> args = new ValueChangedEventArgs<TValue>(prevValue, currValue);
|
---|
116 | @event(sender, args);
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | /// <summary>
|
---|
121 | /// Raises the specified value changed event.
|
---|
122 | /// </summary>
|
---|
123 | /// <typeparam name="T"></typeparam>
|
---|
124 | /// <typeparam name="TValue">The type of the value.</typeparam>
|
---|
125 | /// <param name="event">The event.</param>
|
---|
126 | /// <param name="sender">The sender of event.</param>
|
---|
127 | /// <param name="prevValue">The previous value.</param>
|
---|
128 | /// <param name="currValue">The current value.</param>
|
---|
129 | [DebuggerStepThrough]
|
---|
130 | [DebuggerHidden]
|
---|
131 | public static void Raise<TValue>(this EventHandler<ValueChangedEventArgs<TValue>> @event, object sender, object prevValue, object currValue)
|
---|
132 | {
|
---|
133 | if (@event != null)
|
---|
134 | {
|
---|
135 | ValueChangedEventArgs<TValue> args = new ValueChangedEventArgs<TValue>((TValue)prevValue, (TValue)currValue);
|
---|
136 | @event(sender, args);
|
---|
137 | }
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|