EventInfo.cs 2.4 KB

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