EventInfo.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // System.Reflection/EventInfo.cs
  3. //
  4. // Author:
  5. // Paolo Molaro ([email protected])
  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. using System.Diagnostics;
  30. using System.Runtime.InteropServices;
  31. namespace System.Reflection {
  32. #if NET_2_0
  33. [ComVisible (true)]
  34. [ComDefaultInterfaceAttribute (typeof (_EventInfo))]
  35. [Serializable]
  36. #endif
  37. [ClassInterface(ClassInterfaceType.None)]
  38. public abstract class EventInfo : MemberInfo, _EventInfo {
  39. public abstract EventAttributes Attributes {get;}
  40. public Type EventHandlerType {
  41. get {
  42. ParameterInfo[] p;
  43. MethodInfo add = GetAddMethod (true);
  44. p = add.GetParameters ();
  45. if (p.Length > 0) {
  46. Type t = p [0].ParameterType;
  47. /* is it alwasys the first arg?
  48. if (!t.IsSubclassOf (typeof (System.Delegate)))
  49. throw new Exception ("no delegate in event");*/
  50. return t;
  51. } else
  52. return null;
  53. }
  54. }
  55. public bool IsMulticast {get {return true;}}
  56. public bool IsSpecialName {get {return (Attributes & EventAttributes.SpecialName ) != 0;}}
  57. public override MemberTypes MemberType {
  58. get {return MemberTypes.Event;}
  59. }
  60. protected EventInfo() {
  61. }
  62. #if ONLY_1_1
  63. public new Type GetType ()
  64. {
  65. return base.GetType ();
  66. }
  67. #endif
  68. [DebuggerHidden]
  69. [DebuggerStepThrough]
  70. public void AddEventHandler (object target, Delegate handler)
  71. {
  72. MethodInfo add = GetAddMethod ();
  73. if (add == null)
  74. throw new Exception ("No add method!?");
  75. add.Invoke (target, new object [] {handler});
  76. }
  77. public MethodInfo GetAddMethod() {
  78. return GetAddMethod (false);
  79. }
  80. public abstract MethodInfo GetAddMethod(bool nonPublic);
  81. public MethodInfo GetRaiseMethod() {
  82. return GetRaiseMethod (false);
  83. }
  84. public abstract MethodInfo GetRaiseMethod( bool nonPublic);
  85. public MethodInfo GetRemoveMethod() {
  86. return GetRemoveMethod (false);
  87. }
  88. public abstract MethodInfo GetRemoveMethod( bool nonPublic);
  89. #if NET_2_0
  90. public virtual MethodInfo[] GetOtherMethods (bool nonPublic) {
  91. // Shouldn't this be abstract, like the other methods ?
  92. throw new NotImplementedException ();
  93. }
  94. public MethodInfo[] GetOtherMethods () {
  95. return GetOtherMethods (false);
  96. }
  97. #endif
  98. [DebuggerHidden]
  99. [DebuggerStepThrough]
  100. public void RemoveEventHandler (object target, Delegate handler)
  101. {
  102. MethodInfo remove = GetRemoveMethod ();
  103. if (remove == null)
  104. throw new Exception ("No remove method!?");
  105. remove.Invoke (target, new object [] {handler});
  106. }
  107. void _EventInfo.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
  108. {
  109. throw new NotImplementedException ();
  110. }
  111. void _EventInfo.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
  112. {
  113. throw new NotImplementedException ();
  114. }
  115. void _EventInfo.GetTypeInfoCount (out uint pcTInfo)
  116. {
  117. throw new NotImplementedException ();
  118. }
  119. void _EventInfo.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
  120. {
  121. throw new NotImplementedException ();
  122. }
  123. }
  124. }