SignatureHelper.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // System.Reflection.Emit/SignatureHelper.cs
  3. //
  4. // Author:
  5. // Paolo Molaro ([email protected])
  6. //
  7. // (C) 2001 Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. using System.Reflection;
  11. using System.Reflection.Emit;
  12. using System.Globalization;
  13. using System.Runtime.CompilerServices;
  14. using System.Runtime.InteropServices;
  15. namespace System.Reflection.Emit {
  16. [Serializable]
  17. public sealed class SignatureHelper {
  18. internal enum SignatureHelperType {
  19. HELPER_FIELD,
  20. HELPER_LOCAL,
  21. HELPER_METHOD,
  22. HELPER_PROPERTY
  23. }
  24. private ModuleBuilder module;
  25. private Type[] arguments;
  26. private SignatureHelperType type;
  27. private Type returnType;
  28. private CallingConventions callConv;
  29. private CallingConvention unmanagedCallConv;
  30. internal SignatureHelper (ModuleBuilder module, SignatureHelperType type)
  31. {
  32. this.type = type;
  33. this.module = module;
  34. }
  35. public static SignatureHelper GetFieldSigHelper (Module mod)
  36. {
  37. if (!(mod is ModuleBuilder))
  38. throw new NotImplementedException ();
  39. return new SignatureHelper ((ModuleBuilder) mod, SignatureHelperType.HELPER_FIELD);
  40. }
  41. public static SignatureHelper GetLocalVarSigHelper (Module mod)
  42. {
  43. if (!(mod is ModuleBuilder))
  44. throw new NotImplementedException ();
  45. return new SignatureHelper ((ModuleBuilder) mod, SignatureHelperType.HELPER_LOCAL);
  46. }
  47. public static SignatureHelper GetMethodSigHelper( Module mod, CallingConventions callingConvention, Type returnType)
  48. {
  49. return GetMethodSigHelper (mod, callingConvention, (CallingConvention)0, returnType, null);
  50. }
  51. public static SignatureHelper GetMethodSigHelper( Module mod, CallingConvention unmanagedCallingConvention, Type returnType)
  52. {
  53. return GetMethodSigHelper (mod, CallingConventions.Standard, unmanagedCallingConvention, returnType, null);
  54. }
  55. public static SignatureHelper GetMethodSigHelper( Module mod, Type returnType, Type[] parameterTypes)
  56. {
  57. return GetMethodSigHelper (mod, CallingConventions.Standard,
  58. (CallingConvention)0, returnType,
  59. parameterTypes);
  60. }
  61. [MonoTODO]
  62. public static SignatureHelper GetPropertySigHelper( Module mod, Type returnType, Type[] parameterTypes)
  63. {
  64. throw new NotImplementedException ();
  65. }
  66. public void AddArgument (Type clsArgument)
  67. {
  68. if (arguments != null) {
  69. Type[] new_a = new Type [arguments.Length + 1];
  70. System.Array.Copy (arguments, new_a, arguments.Length);
  71. new_a [arguments.Length] = clsArgument;
  72. arguments = new_a;
  73. } else {
  74. arguments = new Type [1];
  75. arguments [0] = clsArgument;
  76. }
  77. }
  78. [MonoTODO]
  79. public void AddSentinel ()
  80. {
  81. throw new NotImplementedException ();
  82. }
  83. [MonoTODO]
  84. public override bool Equals (object obj)
  85. {
  86. throw new NotImplementedException ();
  87. }
  88. [MonoTODO]
  89. public override int GetHashCode ()
  90. {
  91. throw new NotImplementedException ();
  92. }
  93. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  94. internal extern byte[] get_signature_local ();
  95. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  96. internal extern byte[] get_signature_field ();
  97. public byte[] GetSignature ()
  98. {
  99. switch (type) {
  100. case SignatureHelperType.HELPER_LOCAL:
  101. return get_signature_local ();
  102. case SignatureHelperType.HELPER_FIELD:
  103. return get_signature_field ();
  104. default:
  105. throw new NotImplementedException ();
  106. }
  107. }
  108. public override string ToString() {
  109. return "SignatureHelper";
  110. }
  111. internal static SignatureHelper GetMethodSigHelper( Module mod, CallingConventions callConv, CallingConvention unmanagedCallConv, Type returnType,
  112. Type [] parameters)
  113. {
  114. if (!(mod is ModuleBuilder))
  115. throw new NotImplementedException ();
  116. SignatureHelper helper =
  117. new SignatureHelper ((ModuleBuilder)mod, SignatureHelperType.HELPER_METHOD);
  118. helper.returnType = returnType;
  119. helper.callConv = callConv;
  120. helper.unmanagedCallConv = unmanagedCallConv;
  121. if (parameters != null) {
  122. helper.arguments = new Type [parameters.Length];
  123. for (int i = 0; i < parameters.Length; ++i)
  124. helper.arguments [i] = parameters [i];
  125. }
  126. return helper;
  127. }
  128. }
  129. }