MonoEvent.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. return info.add_method;
  62. }
  63. public override MethodInfo GetRaiseMethod( bool nonPublic) {
  64. MonoEventInfo info;
  65. MonoEventInfo.get_event_info (this, out info);
  66. return info.raise_method;
  67. }
  68. public override MethodInfo GetRemoveMethod( bool nonPublic) {
  69. MonoEventInfo info;
  70. MonoEventInfo.get_event_info (this, out info);
  71. return info.remove_method;
  72. }
  73. #if NET_2_0
  74. public override MethodInfo[] GetOtherMethods (bool nonPublic) {
  75. MonoEventInfo info;
  76. MonoEventInfo.get_event_info (this, out info);
  77. return info.other_methods;
  78. }
  79. #endif
  80. public override Type DeclaringType {
  81. get {
  82. MonoEventInfo info;
  83. MonoEventInfo.get_event_info (this, out info);
  84. return info.declaring_type;
  85. }
  86. }
  87. public override Type ReflectedType {
  88. get {
  89. MonoEventInfo info;
  90. MonoEventInfo.get_event_info (this, out info);
  91. return info.reflected_type;
  92. }
  93. }
  94. public override string Name {
  95. get {
  96. MonoEventInfo info;
  97. MonoEventInfo.get_event_info (this, out info);
  98. return info.name;
  99. }
  100. }
  101. public override string ToString () {
  102. return EventHandlerType + " " + Name;
  103. }
  104. }
  105. }