2008-11-17 Rodrigo Kumpera <rkumpera@novell.com>
[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 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System.Diagnostics;
31 using System.Runtime.InteropServices;
32
33 namespace System.Reflection {
34
35 #if NET_2_0
36         [ComVisible (true)]
37         [ComDefaultInterfaceAttribute (typeof (_EventInfo))]
38         [Serializable]
39 #endif
40         [ClassInterface(ClassInterfaceType.None)]
41         public abstract class EventInfo : MemberInfo, _EventInfo {
42
43                 public abstract EventAttributes Attributes {get;}
44
45                 public Type EventHandlerType {
46                         get {
47                                 ParameterInfo[] p;
48                                 MethodInfo add = GetAddMethod (true);
49                                 p = add.GetParameters ();
50                                 if (p.Length > 0) {
51                                         Type t = p [0].ParameterType;
52                                         /* is it alwasys the first arg?
53                                         if (!t.IsSubclassOf (typeof (System.Delegate)))
54                                                 throw new Exception ("no delegate in event");*/
55                                         return t;
56                                 } else
57                                         return null;
58                         }
59                 }
60                 public bool IsMulticast {get {return true;}}
61                 public bool IsSpecialName {get {return (Attributes & EventAttributes.SpecialName ) != 0;}}
62                 public override MemberTypes MemberType {
63                         get {return MemberTypes.Event;}
64                 }
65
66                 protected EventInfo() {
67                 }
68
69 #if ONLY_1_1
70                 public new Type GetType ()
71                 {
72                         return base.GetType ();
73                 }
74 #endif
75
76                 [DebuggerHidden]
77                 [DebuggerStepThrough]
78                 public void AddEventHandler (object target, Delegate handler)
79                 {
80                         MethodInfo add = GetAddMethod ();
81                         if (add == null)
82                                 throw new Exception ("No add method!?");
83
84                         add.Invoke (target, new object [] {handler});
85                 }
86
87                 public MethodInfo GetAddMethod() {
88                         return GetAddMethod (false);
89                 }
90                 public abstract MethodInfo GetAddMethod(bool nonPublic);
91                 public MethodInfo GetRaiseMethod() {
92                         return GetRaiseMethod (false);
93                 }
94                 public abstract MethodInfo GetRaiseMethod( bool nonPublic);
95                 public MethodInfo GetRemoveMethod() {
96                         return GetRemoveMethod (false);
97                 }
98                 public abstract MethodInfo GetRemoveMethod( bool nonPublic);
99
100 #if NET_2_0
101                 public virtual MethodInfo[] GetOtherMethods (bool nonPublic) {
102                         // implemented by the derived class
103                         return new MethodInfo [0];
104                 }
105
106                 public MethodInfo[] GetOtherMethods () {
107                         return GetOtherMethods (false);
108                 }
109 #endif          
110
111                 [DebuggerHidden]
112                 [DebuggerStepThrough]
113                 public void RemoveEventHandler (object target, Delegate handler)
114                 {
115                         MethodInfo remove = GetRemoveMethod ();
116                         if (remove == null)
117                                 throw new Exception ("No remove method!?");
118
119                         remove.Invoke (target, new object [] {handler});
120                 }
121
122                 void _EventInfo.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
123                 {
124                         throw new NotImplementedException ();
125                 }
126
127                 void _EventInfo.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
128                 {
129                         throw new NotImplementedException ();
130                 }
131
132                 void _EventInfo.GetTypeInfoCount (out uint pcTInfo)
133                 {
134                         throw new NotImplementedException ();
135                 }
136
137                 void _EventInfo.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
138                 {
139                         throw new NotImplementedException ();
140                 }
141         }
142 }