2 Copyright (C) 2009-2012 Jeroen Frijters
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
24 using System.Collections.Generic;
25 using System.Diagnostics;
27 namespace IKVM.Reflection
29 public abstract class EventInfo : MemberInfo
31 // prevent external subclasses
36 public sealed override MemberTypes MemberType
38 get { return MemberTypes.Event; }
41 public abstract EventAttributes Attributes { get; }
42 public abstract MethodInfo GetAddMethod(bool nonPublic);
43 public abstract MethodInfo GetRaiseMethod(bool nonPublic);
44 public abstract MethodInfo GetRemoveMethod(bool nonPublic);
45 public abstract MethodInfo[] GetOtherMethods(bool nonPublic);
46 public abstract MethodInfo[] __GetMethods();
47 public abstract Type EventHandlerType { get; }
48 internal abstract bool IsPublic { get; }
49 internal abstract bool IsNonPrivate { get; }
50 internal abstract bool IsStatic { get; }
52 public bool IsSpecialName
54 get { return (Attributes & EventAttributes.SpecialName) != 0; }
57 public MethodInfo GetAddMethod()
59 return GetAddMethod(false);
62 public MethodInfo GetRaiseMethod()
64 return GetRaiseMethod(false);
67 public MethodInfo GetRemoveMethod()
69 return GetRemoveMethod(false);
72 public MethodInfo[] GetOtherMethods()
74 return GetOtherMethods(false);
77 internal virtual EventInfo BindTypeParameters(Type type)
79 return new GenericEventInfo(this.DeclaringType.BindTypeParameters(type), this);
82 public override string ToString()
84 return this.DeclaringType.ToString() + " " + Name;
87 internal sealed override bool BindingFlagsMatch(BindingFlags flags)
89 return BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
90 && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static, BindingFlags.Instance);
93 internal sealed override bool BindingFlagsMatchInherited(BindingFlags flags)
96 && BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
97 && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static | BindingFlags.FlattenHierarchy, BindingFlags.Instance);
100 internal sealed override MemberInfo SetReflectedType(Type type)
102 return new EventInfoWithReflectedType(type, this);
105 internal sealed override List<CustomAttributeData> GetPseudoCustomAttributes(Type attributeType)
107 // events don't have pseudo custom attributes
112 sealed class EventInfoWithReflectedType : EventInfo
114 private readonly Type reflectedType;
115 private readonly EventInfo eventInfo;
117 internal EventInfoWithReflectedType(Type reflectedType, EventInfo eventInfo)
119 Debug.Assert(reflectedType != eventInfo.DeclaringType);
120 this.reflectedType = reflectedType;
121 this.eventInfo = eventInfo;
124 public override EventAttributes Attributes
126 get { return eventInfo.Attributes; }
129 public override MethodInfo GetAddMethod(bool nonPublic)
131 return SetReflectedType(eventInfo.GetAddMethod(nonPublic), reflectedType);
134 public override MethodInfo GetRaiseMethod(bool nonPublic)
136 return SetReflectedType(eventInfo.GetRaiseMethod(nonPublic), reflectedType);
139 public override MethodInfo GetRemoveMethod(bool nonPublic)
141 return SetReflectedType(eventInfo.GetRemoveMethod(nonPublic), reflectedType);
144 public override MethodInfo[] GetOtherMethods(bool nonPublic)
146 return SetReflectedType(eventInfo.GetOtherMethods(nonPublic), reflectedType);
149 public override MethodInfo[] __GetMethods()
151 return SetReflectedType(eventInfo.__GetMethods(), reflectedType);
154 public override Type EventHandlerType
156 get { return eventInfo.EventHandlerType; }
159 internal override bool IsPublic
161 get { return eventInfo.IsPublic; }
164 internal override bool IsNonPrivate
166 get { return eventInfo.IsNonPrivate; }
169 internal override bool IsStatic
171 get { return eventInfo.IsStatic; }
174 internal override EventInfo BindTypeParameters(Type type)
176 return eventInfo.BindTypeParameters(type);
179 public override string ToString()
181 return eventInfo.ToString();
184 public override bool __IsMissing
186 get { return eventInfo.__IsMissing; }
189 public override Type DeclaringType
191 get { return eventInfo.DeclaringType; }
194 public override Type ReflectedType
196 get { return reflectedType; }
199 public override bool Equals(object obj)
201 EventInfoWithReflectedType other = obj as EventInfoWithReflectedType;
203 && other.reflectedType == reflectedType
204 && other.eventInfo == eventInfo;
207 public override int GetHashCode()
209 return reflectedType.GetHashCode() ^ eventInfo.GetHashCode();
212 public override int MetadataToken
214 get { return eventInfo.MetadataToken; }
217 public override Module Module
219 get { return eventInfo.Module; }
222 public override string Name
224 get { return eventInfo.Name; }
227 internal override bool IsBaked
229 get { return eventInfo.IsBaked; }
232 internal override int GetCurrentToken()
234 return eventInfo.GetCurrentToken();