2003-10-17 Pedro Mart�nez Juli� <yoros@wanadoo.es>
[mono.git] / mcs / class / corlib / System.Reflection / EventInfo.cs
1 //
2 // System.Reflection/EventInfo.cs
3 //
4 // Author:
5 //   Paolo Molaro (lupus@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System;
11 using System.Reflection;
12
13 namespace System.Reflection {
14         public abstract class EventInfo : MemberInfo {
15
16                 public abstract EventAttributes Attributes {get;}
17
18                 public Type EventHandlerType {
19                         get {
20                                 ParameterInfo[] p;
21                                 MethodInfo add = GetAddMethod (true);
22                                 p = add.GetParameters ();
23                                 if (p.Length > 0) {
24                                         Type t = p [0].ParameterType;
25                                         /* is it alwasys the first arg?
26                                         if (!t.IsSubclassOf (typeof (System.Delegate)))
27                                                 throw new Exception ("no delegate in event");*/
28                                         return t;
29                                 } else
30                                         return null;
31                         }
32                 }
33                 public bool IsMulticast {get {return true;}}
34                 public bool IsSpecialName {get {return (Attributes & EventAttributes.SpecialName ) != 0;}}
35                 public override MemberTypes MemberType {
36                         get {return MemberTypes.Event;}
37                 }
38
39                 protected EventInfo() {
40                 }
41
42                 public void AddEventHandler (object target, Delegate handler)
43                 {
44                         MethodInfo add = GetAddMethod ();
45                         if (add == null)
46                                 throw new Exception ("No add method!?");
47
48                         add.Invoke (target, new object [] {handler});
49                 }
50
51                 public MethodInfo GetAddMethod() {
52                         return GetAddMethod (false);
53                 }
54                 public abstract MethodInfo GetAddMethod(bool nonPublic);
55                 public MethodInfo GetRaiseMethod() {
56                         return GetRaiseMethod (false);
57                 }
58                 public abstract MethodInfo GetRaiseMethod( bool nonPublic);
59                 public MethodInfo GetRemoveMethod() {
60                         return GetRemoveMethod (false);
61                 }
62                 public abstract MethodInfo GetRemoveMethod( bool nonPublic);
63
64                 public void RemoveEventHandler (object target, Delegate handler)
65                 {
66                         MethodInfo remove = GetRemoveMethod ();
67                         if (remove == null)
68                                 throw new Exception ("No remove method!?");
69
70                         remove.Invoke (target, new object [] {handler});
71                 }
72
73                 public override bool IsDefined (Type attributeType, bool inherit) {
74                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
75                 }
76
77                 public override object[] GetCustomAttributes( bool inherit) {
78                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
79                 }
80                 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
81                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
82                 }
83                 public override Type ReflectedType {
84                         get {
85                                 return null;
86                         }
87                 }
88                 public override Type DeclaringType {
89                         get {
90                                 return null;
91                         }
92                 }
93
94                 public override String Name {
95                         get {
96                                 return "Eventname";
97                         }
98                 }
99
100         }
101 }