MonoEvent.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  45. internal static extern void get_event_info (MonoEvent ev, out MonoEventInfo info);
  46. }
  47. internal sealed class MonoEvent: EventInfo {
  48. IntPtr klass;
  49. IntPtr handle;
  50. public override EventAttributes Attributes {
  51. get {
  52. MonoEventInfo info;
  53. MonoEventInfo.get_event_info (this, out info);
  54. return info.attrs;
  55. }
  56. }
  57. public override MethodInfo GetAddMethod(bool nonPublic) {
  58. MonoEventInfo info;
  59. MonoEventInfo.get_event_info (this, out info);
  60. return info.add_method;
  61. }
  62. public override MethodInfo GetRaiseMethod( bool nonPublic) {
  63. MonoEventInfo info;
  64. MonoEventInfo.get_event_info (this, out info);
  65. return info.raise_method;
  66. }
  67. public override MethodInfo GetRemoveMethod( bool nonPublic) {
  68. MonoEventInfo info;
  69. MonoEventInfo.get_event_info (this, out info);
  70. return info.remove_method;
  71. }
  72. public override Type DeclaringType {
  73. get {
  74. MonoEventInfo info;
  75. MonoEventInfo.get_event_info (this, out info);
  76. return info.declaring_type;
  77. }
  78. }
  79. public override Type ReflectedType {
  80. get {
  81. MonoEventInfo info;
  82. MonoEventInfo.get_event_info (this, out info);
  83. return info.reflected_type;
  84. }
  85. }
  86. public override string Name {
  87. get {
  88. MonoEventInfo info;
  89. MonoEventInfo.get_event_info (this, out info);
  90. return info.name;
  91. }
  92. }
  93. public override string ToString () {
  94. return EventHandlerType + " " + Name;
  95. }
  96. }
  97. }