2003-12-17 Zoltan Varga <vargaz@freemail.hu>
[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 using System.Runtime.InteropServices;
13
14 namespace System.Reflection {
15
16         [ClassInterface(ClassInterfaceType.AutoDual)]
17         public abstract class EventInfo : MemberInfo {
18
19                 public abstract EventAttributes Attributes {get;}
20
21                 public Type EventHandlerType {
22                         get {
23                                 ParameterInfo[] p;
24                                 MethodInfo add = GetAddMethod (true);
25                                 p = add.GetParameters ();
26                                 if (p.Length > 0) {
27                                         Type t = p [0].ParameterType;
28                                         /* is it alwasys the first arg?
29                                         if (!t.IsSubclassOf (typeof (System.Delegate)))
30                                                 throw new Exception ("no delegate in event");*/
31                                         return t;
32                                 } else
33                                         return null;
34                         }
35                 }
36                 public bool IsMulticast {get {return true;}}
37                 public bool IsSpecialName {get {return (Attributes & EventAttributes.SpecialName ) != 0;}}
38                 public override MemberTypes MemberType {
39                         get {return MemberTypes.Event;}
40                 }
41
42                 protected EventInfo() {
43                 }
44
45                 public void AddEventHandler (object target, Delegate handler)
46                 {
47                         MethodInfo add = GetAddMethod ();
48                         if (add == null)
49                                 throw new Exception ("No add method!?");
50
51                         add.Invoke (target, new object [] {handler});
52                 }
53
54                 public MethodInfo GetAddMethod() {
55                         return GetAddMethod (false);
56                 }
57                 public abstract MethodInfo GetAddMethod(bool nonPublic);
58                 public MethodInfo GetRaiseMethod() {
59                         return GetRaiseMethod (false);
60                 }
61                 public abstract MethodInfo GetRaiseMethod( bool nonPublic);
62                 public MethodInfo GetRemoveMethod() {
63                         return GetRemoveMethod (false);
64                 }
65                 public abstract MethodInfo GetRemoveMethod( bool nonPublic);
66
67                 public void RemoveEventHandler (object target, Delegate handler)
68                 {
69                         MethodInfo remove = GetRemoveMethod ();
70                         if (remove == null)
71                                 throw new Exception ("No remove method!?");
72
73                         remove.Invoke (target, new object [] {handler});
74                 }
75
76                 public override bool IsDefined (Type attributeType, bool inherit) {
77                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
78                 }
79
80                 public override object[] GetCustomAttributes( bool inherit) {
81                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
82                 }
83                 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
84                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
85                 }
86                 public override Type ReflectedType {
87                         get {
88                                 return null;
89                         }
90                 }
91                 public override Type DeclaringType {
92                         get {
93                                 return null;
94                         }
95                 }
96
97                 public override String Name {
98                         get {
99                                 return "Eventname";
100                         }
101                 }
102
103         }
104 }