ParameterBuilder.cs 2.5 KB

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