EventInfo.cs 2.5 KB

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