MonoMethodMessage.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //
  2. // System.Runtime.Remoting.Messaging.MonoMethodMessage.cs
  3. //
  4. // Author:
  5. // Dietmar Maurer ([email protected])
  6. //
  7. // (C) Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.Reflection;
  12. using System.Runtime.CompilerServices;
  13. namespace System.Runtime.Remoting.Messaging {
  14. public class MonoMethodMessage : IMethodCallMessage, IMethodReturnMessage {
  15. MonoMethod method;
  16. object [] args;
  17. string [] names;
  18. byte [] arg_types; /* 1 == IN; 2 == OUT ; 3 = INOUT */
  19. public LogicalCallContext ctx;
  20. public object rval;
  21. public Exception exc;
  22. string uri;
  23. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  24. internal extern void InitMessage (MonoMethod method, object [] out_args);
  25. public MonoMethodMessage (MethodBase method, object [] out_args)
  26. {
  27. InitMessage ((MonoMethod)method, out_args);
  28. }
  29. public MonoMethodMessage (Type type, string method_name, object [] in_args)
  30. {
  31. // fixme: consider arg types
  32. MethodInfo minfo = type.GetMethod (method_name);
  33. InitMessage ((MonoMethod)minfo, null);
  34. int len = in_args.Length;
  35. for (int i = 0; i < len; i++) {
  36. args [i] = in_args [i];
  37. }
  38. }
  39. public IDictionary Properties {
  40. get {
  41. return null;
  42. }
  43. }
  44. public int ArgCount {
  45. get {
  46. return args.Length;
  47. }
  48. }
  49. public object [] Args {
  50. get {
  51. return args;
  52. }
  53. }
  54. public bool HasVarArgs {
  55. get {
  56. return false;
  57. }
  58. }
  59. public LogicalCallContext LogicalCallContext {
  60. get {
  61. return ctx;
  62. }
  63. }
  64. public MethodBase MethodBase {
  65. get {
  66. return method;
  67. }
  68. }
  69. public string MethodName {
  70. get {
  71. return method.Name;
  72. }
  73. }
  74. public object MethodSignature {
  75. get {
  76. return null;
  77. }
  78. }
  79. public string TypeName {
  80. get {
  81. return null;
  82. }
  83. }
  84. public string Uri {
  85. get {
  86. return uri;
  87. }
  88. set {
  89. uri = value;
  90. }
  91. }
  92. public object GetArg (int arg_num)
  93. {
  94. return args [arg_num];
  95. }
  96. public string GetArgName (int arg_num)
  97. {
  98. return names [arg_num];
  99. }
  100. public int InArgCount {
  101. get {
  102. int count = 0;
  103. foreach (byte t in arg_types) {
  104. if ((t & 1) != 0) count++;
  105. }
  106. return count;
  107. }
  108. }
  109. public object [] InArgs {
  110. get {
  111. int i, j, count = InArgCount;
  112. object [] inargs = new object [count];
  113. i = j = 0;
  114. foreach (byte t in arg_types) {
  115. if ((t & 1) != 0)
  116. inargs [j++] = args [i];
  117. i++;
  118. }
  119. return inargs;
  120. }
  121. }
  122. public object GetInArg (int arg_num)
  123. {
  124. int i = 0, j = 0;
  125. foreach (byte t in arg_types) {
  126. if ((t & 1) != 0) {
  127. if (j++ == arg_num)
  128. return args [i];
  129. }
  130. i++;
  131. }
  132. return null;
  133. }
  134. public string GetInArgName (int arg_num)
  135. {
  136. int i = 0, j = 0;
  137. foreach (byte t in arg_types) {
  138. if ((t & 1) != 0) {
  139. if (j++ == arg_num)
  140. return names [i];
  141. }
  142. i++;
  143. }
  144. return null;
  145. }
  146. public Exception Exception {
  147. get {
  148. return exc;
  149. }
  150. }
  151. public int OutArgCount {
  152. get {
  153. int count = 0;
  154. foreach (byte t in arg_types) {
  155. if ((t & 2) != 0) count++;
  156. }
  157. return count;
  158. }
  159. }
  160. public object [] OutArgs {
  161. get {
  162. int i, j, count = OutArgCount;
  163. object [] outargs = new object [count];
  164. i = j = 0;
  165. foreach (byte t in arg_types) {
  166. if ((t & 2) != 0)
  167. outargs [j++] = args [i];
  168. i++;
  169. }
  170. return outargs;
  171. }
  172. }
  173. public object ReturnValue {
  174. get {
  175. return rval;
  176. }
  177. }
  178. public object GetOutArg (int arg_num)
  179. {
  180. int i = 0, j = 0;
  181. foreach (byte t in arg_types) {
  182. if ((t & 2) != 0) {
  183. if (j++ == arg_num)
  184. return args [i];
  185. }
  186. i++;
  187. }
  188. return null;
  189. }
  190. public string GetOutArgName (int arg_num)
  191. {
  192. int i = 0, j = 0;
  193. foreach (byte t in arg_types) {
  194. if ((t & 2) != 0) {
  195. if (j++ == arg_num)
  196. return names [i];
  197. }
  198. i++;
  199. }
  200. return null;
  201. }
  202. }
  203. }