Tue Jul 2 18:34:49 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / ParameterBuilder.cs
1
2
3 //
4 // System.Reflection.Emit/ParameterBuilder.cs
5 //
6 // Author:
7 //   Paolo Molaro (lupus@ximian.com)
8 //
9 // (C) 2001 Ximian, Inc.  http://www.ximian.com
10 //
11
12 using System;
13 using System.Reflection;
14 using System.Reflection.Emit;
15 using System.Globalization;
16 using System.Runtime.CompilerServices;
17 using System.Runtime.InteropServices;
18
19 namespace System.Reflection.Emit {
20         public class ParameterBuilder {
21                 private MethodBase methodb; /* MethodBuilder or ConstructorBuilder */
22                 private string name;
23                 private CustomAttributeBuilder[] cattrs;
24                 private UnmanagedMarshal marshal_info;
25                 private ParameterAttributes attrs;
26                 private int position;
27                 private int table_idx;
28                 
29                 internal ParameterBuilder (MethodBase mb, int pos, ParameterAttributes attributes, string strParamName) {
30                         name = strParamName;
31                         position = pos;
32                         attrs = attributes;
33                         methodb = mb;
34                         table_idx = mb.get_next_table_index (this, 0x08, true);
35                 }
36
37                 public virtual int Attributes {
38                         get {return (int)attrs;}
39                 }
40                 public bool IsIn {
41                         get {return ((int)attrs & (int)ParameterAttributes.In) != 0;}
42                 }
43                 public bool IsOut {
44                         get {return ((int)attrs & (int)ParameterAttributes.Out) != 0;}
45                 }
46                 public bool IsOptional {
47                         get {return ((int)attrs & (int)ParameterAttributes.Optional) != 0;}
48                 }
49                 public virtual string Name {
50                         get {return name;}
51                 }
52                 public virtual int Position {
53                         get {return position;}
54                 }
55
56                 public virtual ParameterToken GetToken() {
57                         return new ParameterToken (0x08 | table_idx);
58                 }
59
60                 [MonoTODO]
61                 public virtual void SetConstant( object defaultValue) {
62                         /* FIXME */
63                 }
64                 
65                 public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
66                         string attrname = customBuilder.Ctor.ReflectedType.FullName;
67                         if (attrname == "System.Runtime.InteropServices.InAttribute") {
68                                 attrs |= ParameterAttributes.In;
69                                 return;
70                         } else if (attrname == "System.Runtime.InteropServices.OutAttribute") {
71                                 attrs |= ParameterAttributes.Out;
72                                 return;
73                         } else if (attrname == "System.Runtime.InteropServices.OptionalAttribute") {
74                                 attrs |= ParameterAttributes.Optional;
75                                 return;
76                         } else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute") {
77                                 marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, true);
78                                 /* FIXME: check for errors */
79                                 return;
80                         }
81                         if (cattrs != null) {
82                                 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
83                                 cattrs.CopyTo (new_array, 0);
84                                 new_array [cattrs.Length] = customBuilder;
85                                 cattrs = new_array;
86                         } else {
87                                 cattrs = new CustomAttributeBuilder [1];
88                                 cattrs [0] = customBuilder;
89                         }
90                 }
91                 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
92                         SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
93                 }
94
95                 public virtual void SetMarshal( UnmanagedMarshal unmanagedMarshal) {
96                         marshal_info = unmanagedMarshal;
97                         attrs |= ParameterAttributes.HasFieldMarshal;
98                 }
99
100
101
102
103
104         }
105 }
106