mscorlib(4.0.0.0) API with additions
EventInfo.cs
1 using System.Diagnostics;
5 
6 namespace System.Reflection
7 {
10  [ClassInterface(ClassInterfaceType.None)]
11  [ComDefaultInterface(typeof(_EventInfo))]
12  [ComVisible(true)]
13  [__DynamicallyInvokable]
14  [PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust")]
15  public abstract class EventInfo : MemberInfo, _EventInfo
16  {
19  public override MemberTypes MemberType => MemberTypes.Event;
20 
23  [__DynamicallyInvokable]
24  public abstract EventAttributes Attributes
25  {
26  [__DynamicallyInvokable]
27  get;
28  }
29 
32  [__DynamicallyInvokable]
33  public virtual MethodInfo AddMethod
34  {
35  [__DynamicallyInvokable]
36  get
37  {
38  return GetAddMethod(nonPublic: true);
39  }
40  }
41 
44  [__DynamicallyInvokable]
45  public virtual MethodInfo RemoveMethod
46  {
47  [__DynamicallyInvokable]
48  get
49  {
50  return GetRemoveMethod(nonPublic: true);
51  }
52  }
53 
56  [__DynamicallyInvokable]
57  public virtual MethodInfo RaiseMethod
58  {
59  [__DynamicallyInvokable]
60  get
61  {
62  return GetRaiseMethod(nonPublic: true);
63  }
64  }
65 
69  [__DynamicallyInvokable]
70  public virtual Type EventHandlerType
71  {
72  [__DynamicallyInvokable]
73  get
74  {
75  MethodInfo addMethod = GetAddMethod(nonPublic: true);
76  ParameterInfo[] parametersNoCopy = addMethod.GetParametersNoCopy();
77  Type typeFromHandle = typeof(Delegate);
78  for (int i = 0; i < parametersNoCopy.Length; i++)
79  {
80  Type parameterType = parametersNoCopy[i].ParameterType;
81  if (parameterType.IsSubclassOf(typeFromHandle))
82  {
83  return parameterType;
84  }
85  }
86  return null;
87  }
88  }
89 
93  [__DynamicallyInvokable]
94  public bool IsSpecialName
95  {
96  [__DynamicallyInvokable]
97  get
98  {
99  return (Attributes & EventAttributes.SpecialName) != EventAttributes.None;
100  }
101  }
102 
107  [__DynamicallyInvokable]
108  public virtual bool IsMulticast
109  {
110  [__DynamicallyInvokable]
111  get
112  {
113  Type eventHandlerType = EventHandlerType;
114  Type typeFromHandle = typeof(MulticastDelegate);
115  return typeFromHandle.IsAssignableFrom(eventHandlerType);
116  }
117  }
118 
124  [__DynamicallyInvokable]
125  public static bool operator ==(EventInfo left, EventInfo right)
126  {
127  if ((object)left == right)
128  {
129  return true;
130  }
131  if ((object)left == null || (object)right == null || left is RuntimeEventInfo || right is RuntimeEventInfo)
132  {
133  return false;
134  }
135  return left.Equals(right);
136  }
137 
143  [__DynamicallyInvokable]
144  public static bool operator !=(EventInfo left, EventInfo right)
145  {
146  return !(left == right);
147  }
148 
153  [__DynamicallyInvokable]
154  public override bool Equals(object obj)
155  {
156  return base.Equals(obj);
157  }
158 
161  [__DynamicallyInvokable]
162  public override int GetHashCode()
163  {
164  return base.GetHashCode();
165  }
166 
172  public virtual MethodInfo[] GetOtherMethods(bool nonPublic)
173  {
174  throw new NotImplementedException();
175  }
176 
183  [__DynamicallyInvokable]
184  public abstract MethodInfo GetAddMethod(bool nonPublic);
185 
192  [__DynamicallyInvokable]
193  public abstract MethodInfo GetRemoveMethod(bool nonPublic);
194 
201  [__DynamicallyInvokable]
202  public abstract MethodInfo GetRaiseMethod(bool nonPublic);
203 
207  {
208  return GetOtherMethods(nonPublic: false);
209  }
210 
213  [__DynamicallyInvokable]
215  {
216  return GetAddMethod(nonPublic: false);
217  }
218 
221  [__DynamicallyInvokable]
223  {
224  return GetRemoveMethod(nonPublic: false);
225  }
226 
229  [__DynamicallyInvokable]
231  {
232  return GetRaiseMethod(nonPublic: false);
233  }
234 
244  [DebuggerStepThrough]
245  [DebuggerHidden]
246  [__DynamicallyInvokable]
247  public virtual void AddEventHandler(object target, Delegate handler)
248  {
249  MethodInfo addMethod = GetAddMethod();
250  if (addMethod == null)
251  {
252  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoPublicAddMethod"));
253  }
254  if (addMethod.ReturnType == typeof(EventRegistrationToken))
255  {
256  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotSupportedOnWinRTEvent"));
257  }
258  addMethod.Invoke(target, new object[1]
259  {
260  handler
261  });
262  }
263 
273  [DebuggerStepThrough]
274  [DebuggerHidden]
275  [__DynamicallyInvokable]
276  public virtual void RemoveEventHandler(object target, Delegate handler)
277  {
278  MethodInfo removeMethod = GetRemoveMethod();
279  if (removeMethod == null)
280  {
281  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoPublicRemoveMethod"));
282  }
283  ParameterInfo[] parametersNoCopy = removeMethod.GetParametersNoCopy();
284  if (parametersNoCopy[0].ParameterType == typeof(EventRegistrationToken))
285  {
286  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotSupportedOnWinRTEvent"));
287  }
288  removeMethod.Invoke(target, new object[1]
289  {
290  handler
291  });
292  }
293 
297  {
298  return GetType();
299  }
300 
304  void _EventInfo.GetTypeInfoCount(out uint pcTInfo)
305  {
306  throw new NotImplementedException();
307  }
308 
314  void _EventInfo.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
315  {
316  throw new NotImplementedException();
317  }
318 
326  void _EventInfo.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
327  {
328  throw new NotImplementedException();
329  }
330 
341  void _EventInfo.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
342  {
343  throw new NotImplementedException();
344  }
345  }
346 }
Obtains information about the attributes of a member and provides access to member metadata.
Definition: MemberInfo.cs:14
Discovers the attributes of a parameter and provides access to parameter metadata.
void GetTypeInfoCount(out uint pcTInfo)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
MethodInfo GetAddMethod()
Returns the method used to add an event handler delegate to the event source.
Definition: EventInfo.cs:214
static bool operator==(EventInfo left, EventInfo right)
Indicates whether two T:System.Reflection.EventInfo objects are equal.
Definition: EventInfo.cs:125
MethodInfo GetRaiseMethod()
Returns the method that is called when the event is raised.
Definition: EventInfo.cs:230
A token that is returned when an event handler is added to a Windows Runtime event....
Discovers the attributes of a method and provides access to method metadata.
Definition: MethodInfo.cs:13
virtual bool IsMulticast
Gets a value indicating whether the event is multicast.
Definition: EventInfo.cs:109
override int GetHashCode()
Returns the hash code for this instance.
Definition: EventInfo.cs:162
MethodInfo GetRemoveMethod()
Returns the method used to remove an event handler delegate from the event source.
Definition: EventInfo.cs:222
void Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
Provides access to properties and methods exposed by an object.
Represents a multicast delegate; that is, a delegate that can have more than one element in its invoc...
Definition: __Canon.cs:3
virtual Type ReturnType
Gets the return type of this method.
Definition: MethodInfo.cs:23
bool IsSpecialName
Gets a value indicating whether the EventInfo has a name with a special meaning.
Definition: EventInfo.cs:95
virtual MethodInfo [] GetOtherMethods(bool nonPublic)
Returns the methods that have been associated with the event in metadata using the ....
Definition: EventInfo.cs:172
override bool Equals(object obj)
Returns a value that indicates whether this instance is equal to a specified object.
Definition: EventInfo.cs:154
virtual bool IsSubclassOf(Type c)
Determines whether the current T:System.Type derives from the specified T:System.Type.
Definition: Type.cs:2664
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
virtual void RemoveEventHandler(object target, Delegate handler)
Removes an event handler from an event source.
Definition: EventInfo.cs:276
virtual Type EventHandlerType
Gets the Type object of the underlying event-handler delegate associated with this event.
Definition: EventInfo.cs:71
virtual void AddEventHandler(object target, Delegate handler)
Adds an event handler to an event source.
Definition: EventInfo.cs:247
virtual MethodInfo RemoveMethod
Gets the MethodInfo object for removing a method of the event, including non-public methods.
Definition: EventInfo.cs:46
Discovers the attributes of an event and provides access to event metadata.
Definition: EventInfo.cs:15
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Definition: Delegate.cs:15
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
Exposes the public members of the T:System.Reflection.EventInfo class to unmanaged code.
Definition: _EventInfo.cs:11
MethodInfo [] GetOtherMethods()
Returns the public methods that have been associated with an event in metadata using the ....
Definition: EventInfo.cs:206
virtual MethodInfo AddMethod
Gets the T:System.Reflection.MethodInfo object for the M:System.Reflection.EventInfo....
Definition: EventInfo.cs:34
EventAttributes
Specifies the attributes of an event.
void GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
Retrieves the type information for an object, which can be used to get the type information for an in...
abstract EventAttributes Attributes
Gets the attributes for this event.
Definition: EventInfo.cs:25
Specifies that the class can be serialized.
virtual Type ParameterType
Gets the Type of this parameter.
The exception that is thrown when a method call is invalid for the object's current state.
void GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
Maps a set of names to a corresponding set of dispatch identifiers.
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
Specifies that the parameter is an input parameter.
new Type GetType()
Provides COM objects with version-independent access to the M:System.Object.GetType method.
MemberTypes
Marks each type of member that is defined as a derived class of T:System.Reflection....
Definition: MemberTypes.cs:9
override MemberTypes MemberType
Gets a T:System.Reflection.MemberTypes value indicating that this member is an event.
Definition: EventInfo.cs:19
The exception that is thrown when a requested method or operation is not implemented.
virtual bool IsAssignableFrom(Type c)
Determines whether an instance of a specified type can be assigned to an instance of the current type...
Definition: Type.cs:2707
static bool operator !=(EventInfo left, EventInfo right)
Indicates whether two T:System.Reflection.EventInfo objects are not equal.
Definition: EventInfo.cs:144
virtual MethodInfo RaiseMethod
Gets the method that is called when the event is raised, including non-public methods.
Definition: EventInfo.cs:58