ParameterBuilder.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // System.Reflection.Emit/ParameterBuilder.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. public class ParameterBuilder {
  17. private MethodBase methodb; /* MethodBuilder or ConstructorBuilder */
  18. private string name;
  19. private CustomAttributeBuilder[] cattrs;
  20. private UnmanagedMarshal marshal_info;
  21. private ParameterAttributes attrs;
  22. private int position;
  23. private int table_idx;
  24. internal ParameterBuilder (MethodBase mb, int pos, ParameterAttributes attributes, string strParamName) {
  25. name = strParamName;
  26. position = pos;
  27. attrs = attributes;
  28. methodb = mb;
  29. table_idx = mb.get_next_table_index (this, 0x08, true);
  30. }
  31. public virtual int Attributes {
  32. get {return (int)attrs;}
  33. }
  34. public bool IsIn {
  35. get {return ((int)attrs & (int)ParameterAttributes.In) != 0;}
  36. }
  37. public bool IsOut {
  38. get {return ((int)attrs & (int)ParameterAttributes.Out) != 0;}
  39. }
  40. public bool IsOptional {
  41. get {return ((int)attrs & (int)ParameterAttributes.Optional) != 0;}
  42. }
  43. public virtual string Name {
  44. get {return name;}
  45. }
  46. public virtual int Position {
  47. get {return position;}
  48. }
  49. public virtual ParameterToken GetToken() {
  50. return new ParameterToken (0x08 | table_idx);
  51. }
  52. [MonoTODO]
  53. public virtual void SetConstant( object defaultValue) {
  54. /* FIXME */
  55. }
  56. public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
  57. string attrname = customBuilder.Ctor.ReflectedType.FullName;
  58. if (attrname == "System.Runtime.InteropServices.InAttribute") {
  59. attrs |= ParameterAttributes.In;
  60. return;
  61. } else if (attrname == "System.Runtime.InteropServices.OutAttribute") {
  62. attrs |= ParameterAttributes.Out;
  63. return;
  64. } else if (attrname == "System.Runtime.InteropServices.OptionalAttribute") {
  65. attrs |= ParameterAttributes.Optional;
  66. return;
  67. } else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute") {
  68. marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, true);
  69. /* FIXME: check for errors */
  70. return;
  71. }
  72. if (cattrs != null) {
  73. CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
  74. cattrs.CopyTo (new_array, 0);
  75. new_array [cattrs.Length] = customBuilder;
  76. cattrs = new_array;
  77. } else {
  78. cattrs = new CustomAttributeBuilder [1];
  79. cattrs [0] = customBuilder;
  80. }
  81. }
  82. public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
  83. SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
  84. }
  85. public virtual void SetMarshal( UnmanagedMarshal unmanagedMarshal) {
  86. marshal_info = unmanagedMarshal;
  87. attrs |= ParameterAttributes.HasFieldMarshal;
  88. }
  89. }
  90. }