MonoEvent.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // System.Reflection/MonoEvent.cs
  3. //
  4. // Author:
  5. // Paolo Molaro ([email protected])
  6. //
  7. // (C) 2001 Ximian, Inc. http://www.ximian.com
  8. //
  9. //
  10. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.Reflection;
  33. using System.Runtime.CompilerServices;
  34. using System.Runtime.InteropServices;
  35. namespace System.Reflection {
  36. internal struct MonoEventInfo {
  37. public Type declaring_type;
  38. public Type reflected_type;
  39. public String name;
  40. public MethodInfo add_method;
  41. public MethodInfo remove_method;
  42. public MethodInfo raise_method;
  43. public EventAttributes attrs;
  44. public MethodInfo[] other_methods;
  45. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  46. internal static extern void get_event_info (MonoEvent ev, out MonoEventInfo info);
  47. }
  48. internal sealed class MonoEvent: EventInfo {
  49. IntPtr klass;
  50. IntPtr handle;
  51. public override EventAttributes Attributes {
  52. get {
  53. MonoEventInfo info;
  54. MonoEventInfo.get_event_info (this, out info);
  55. return info.attrs;
  56. }
  57. }
  58. public override MethodInfo GetAddMethod(bool nonPublic) {
  59. MonoEventInfo info;
  60. MonoEventInfo.get_event_info (this, out info);
  61. if (nonPublic || (info.add_method != null && info.add_method.IsPublic))
  62. return info.add_method;
  63. return null;
  64. }
  65. public override MethodInfo GetRaiseMethod( bool nonPublic) {
  66. MonoEventInfo info;
  67. MonoEventInfo.get_event_info (this, out info);
  68. if (nonPublic || (info.raise_method != null && info.raise_method.IsPublic))
  69. return info.raise_method;
  70. return null;
  71. }
  72. public override MethodInfo GetRemoveMethod( bool nonPublic) {
  73. MonoEventInfo info;
  74. MonoEventInfo.get_event_info (this, out info);
  75. if (nonPublic || (info.remove_method != null && info.remove_method.IsPublic))
  76. return info.remove_method;
  77. return null;
  78. }
  79. #if NET_2_0
  80. public override MethodInfo[] GetOtherMethods (bool nonPublic) {
  81. MonoEventInfo info;
  82. MonoEventInfo.get_event_info (this, out info);
  83. return info.other_methods;
  84. }
  85. #endif
  86. public override Type DeclaringType {
  87. get {
  88. MonoEventInfo info;
  89. MonoEventInfo.get_event_info (this, out info);
  90. return info.declaring_type;
  91. }
  92. }
  93. public override Type ReflectedType {
  94. get {
  95. MonoEventInfo info;
  96. MonoEventInfo.get_event_info (this, out info);
  97. return info.reflected_type;
  98. }
  99. }
  100. public override string Name {
  101. get {
  102. MonoEventInfo info;
  103. MonoEventInfo.get_event_info (this, out info);
  104. return info.name;
  105. }
  106. }
  107. public override string ToString ()
  108. {
  109. return EventHandlerType + " " + Name;
  110. }
  111. public override bool IsDefined (Type attributeType, bool inherit)
  112. {
  113. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  114. }
  115. public override object[] GetCustomAttributes( bool inherit)
  116. {
  117. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  118. }
  119. public override object[] GetCustomAttributes( Type attributeType, bool inherit)
  120. {
  121. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  122. }
  123. }
  124. }