ReflectionCalls.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //
  2. // MonoTests.System.Runtime.Remoting.ReflectionCalls.cs
  3. //
  4. // Author: Lluis Sanchez Gual ([email protected])
  5. //
  6. // 2003 (C) Copyright, Ximian, Inc.
  7. //
  8. using System;
  9. using System.Reflection;
  10. using System.Collections;
  11. using NUnit.Framework;
  12. namespace MonoTests.System.Runtime.Remoting
  13. {
  14. public abstract class ReflectionCallTest : BaseCallTest
  15. {
  16. public override InstanceSurrogate GetInstanceSurrogate () { return new ReflectionInstanceSurrogate (); }
  17. public override AbstractSurrogate GetAbstractSurrogate () { return new ReflectionAbstractSurrogate (); }
  18. public override InterfaceSurrogate GetInterfaceSurrogate () { return new ReflectionInterfaceSurrogate (); }
  19. public static int Simple (Type type, object target)
  20. {
  21. object[] parms = new object[0];
  22. MethodBase m = type.GetMethod ("Simple");
  23. return (int) m.Invoke (target, parms);
  24. }
  25. public static string PrimitiveParams (Type type, object target, int a, uint b, char c, string d)
  26. {
  27. object[] parms = new object[] {a,b,c,d};
  28. MethodBase m = type.GetMethod ("PrimitiveParams");
  29. return (string) m.Invoke (target, parms);
  30. }
  31. public static string PrimitiveParamsInOut (Type type, object target, ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
  32. {
  33. object[] parms = new object[] {a1,0,b1,0f,c1,'\0',d1,null};
  34. MethodBase m = type.GetMethod ("PrimitiveParamsInOut");
  35. string res = (string) m.Invoke (target, parms);
  36. a1 = (int)parms[0];
  37. b1 = (float)parms[2];
  38. c1 = (char)parms[4];
  39. d1 = (string)parms[6];
  40. a2 = (int)parms[1];
  41. b2 = (float)parms[3];
  42. c2 = (char)parms[5];
  43. d2 = (string)parms[7];
  44. return res;
  45. }
  46. public static Complex ComplexParams (Type type, object target, ArrayList a, Complex b, string c)
  47. {
  48. object[] parms = new object[] {a,b,c};
  49. MethodBase m = type.GetMethod ("ComplexParams");
  50. return (Complex) m.Invoke (target, parms);
  51. }
  52. public static Complex ComplexParamsInOut (Type type, object target, ref ArrayList a, out Complex b, string c)
  53. {
  54. object[] parms = new object[] {a,null,c};
  55. MethodBase m = type.GetMethod ("ComplexParamsInOut");
  56. Complex res = (Complex) m.Invoke (target, parms);
  57. a = (ArrayList) parms[0];
  58. b = (Complex) parms[1];
  59. return res;
  60. }
  61. }
  62. public class ReflectionInstanceSurrogate : InstanceSurrogate
  63. {
  64. public override int Simple ()
  65. {
  66. return ReflectionCallTest.Simple (typeof (RemoteObject), RemoteObject);
  67. }
  68. public override string PrimitiveParams (int a, uint b, char c, string d)
  69. {
  70. return ReflectionCallTest.PrimitiveParams (typeof (RemoteObject), RemoteObject, a, b, c, d);
  71. }
  72. public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
  73. {
  74. return ReflectionCallTest.PrimitiveParamsInOut (typeof (RemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
  75. }
  76. public override Complex ComplexParams (ArrayList a, Complex b, string c)
  77. {
  78. return ReflectionCallTest.ComplexParams (typeof (RemoteObject), RemoteObject, a, b, c);
  79. }
  80. public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, string c)
  81. {
  82. return ReflectionCallTest.ComplexParamsInOut (typeof (RemoteObject), RemoteObject, ref a, out b, c);
  83. }
  84. }
  85. public class ReflectionAbstractSurrogate : AbstractSurrogate
  86. {
  87. public override int Simple ()
  88. {
  89. return ReflectionCallTest.Simple (typeof (AbstractRemoteObject), RemoteObject);
  90. }
  91. public override string PrimitiveParams (int a, uint b, char c, string d)
  92. {
  93. return ReflectionCallTest.PrimitiveParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c, d);
  94. }
  95. public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
  96. {
  97. return ReflectionCallTest.PrimitiveParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
  98. }
  99. public override Complex ComplexParams (ArrayList a, Complex b, string c)
  100. {
  101. return ReflectionCallTest.ComplexParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c);
  102. }
  103. public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, string c)
  104. {
  105. return ReflectionCallTest.ComplexParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a, out b, c);
  106. }
  107. }
  108. public class ReflectionInterfaceSurrogate : InterfaceSurrogate
  109. {
  110. public override int Simple ()
  111. {
  112. return ReflectionCallTest.Simple (typeof (IRemoteObject), RemoteObject);
  113. }
  114. public override string PrimitiveParams (int a, uint b, char c, string d)
  115. {
  116. return ReflectionCallTest.PrimitiveParams (typeof (IRemoteObject), RemoteObject, a, b, c, d);
  117. }
  118. public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, ref char c1, out char c2, ref string d1, out string d2)
  119. {
  120. return ReflectionCallTest.PrimitiveParamsInOut (typeof (IRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2);
  121. }
  122. public override Complex ComplexParams (ArrayList a, Complex b, string c)
  123. {
  124. return ReflectionCallTest.ComplexParams (typeof (IRemoteObject), RemoteObject, a, b, c);
  125. }
  126. public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, string c)
  127. {
  128. return ReflectionCallTest.ComplexParamsInOut (typeof (IRemoteObject), RemoteObject, ref a, out b, c);
  129. }
  130. }
  131. }