4 // System.Reflection.Emit/ParameterBuilder.cs
7 // Paolo Molaro (lupus@ximian.com)
9 // (C) 2001 Ximian, Inc. http://www.ximian.com
13 using System.Reflection;
14 using System.Reflection.Emit;
15 using System.Globalization;
16 using System.Runtime.CompilerServices;
17 using System.Runtime.InteropServices;
19 namespace System.Reflection.Emit {
20 public class ParameterBuilder {
21 private MethodBase methodb; /* MethodBuilder or ConstructorBuilder */
23 private CustomAttributeBuilder[] cattrs;
24 private UnmanagedMarshal marshal_info;
25 private ParameterAttributes attrs;
27 private int table_idx;
29 internal ParameterBuilder (MethodBase mb, int pos, ParameterAttributes attributes, string strParamName) {
34 table_idx = mb.get_next_table_index (this, 0x08, true);
37 public virtual int Attributes {
38 get {return (int)attrs;}
41 get {return ((int)attrs & (int)ParameterAttributes.In) != 0;}
44 get {return ((int)attrs & (int)ParameterAttributes.Out) != 0;}
46 public bool IsOptional {
47 get {return ((int)attrs & (int)ParameterAttributes.Optional) != 0;}
49 public virtual string Name {
52 public virtual int Position {
53 get {return position;}
56 public virtual ParameterToken GetToken() {
57 return new ParameterToken (0x08 | table_idx);
61 public virtual void SetConstant( object defaultValue) {
65 public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
66 string attrname = customBuilder.Ctor.ReflectedType.FullName;
67 if (attrname == "System.Runtime.InteropServices.InAttribute") {
68 attrs |= ParameterAttributes.In;
70 } else if (attrname == "System.Runtime.InteropServices.OutAttribute") {
71 attrs |= ParameterAttributes.Out;
73 } else if (attrname == "System.Runtime.InteropServices.OptionalAttribute") {
74 attrs |= ParameterAttributes.Optional;
76 } else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute") {
77 marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, true);
78 /* FIXME: check for errors */
82 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
83 cattrs.CopyTo (new_array, 0);
84 new_array [cattrs.Length] = customBuilder;
87 cattrs = new CustomAttributeBuilder [1];
88 cattrs [0] = customBuilder;
91 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
92 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
95 public virtual void SetMarshal( UnmanagedMarshal unmanagedMarshal) {
96 marshal_info = unmanagedMarshal;
97 attrs |= ParameterAttributes.HasFieldMarshal;