2003-11-06 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / ParameterBuilder.cs
index 84b029aca7b90dc501a0d1df10f5e5a72daf9f92..02ba64986cda365a729c9c26feb789c68d7dd09e 100755 (executable)
@@ -14,12 +14,14 @@ using System.Reflection;
 using System.Reflection.Emit;
 using System.Globalization;
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 
 namespace System.Reflection.Emit {
        public class ParameterBuilder {
                private MethodBase methodb; /* MethodBuilder or ConstructorBuilder */
                private string name;
                private CustomAttributeBuilder[] cattrs;
+               private UnmanagedMarshal marshal_info;
                private ParameterAttributes attrs;
                private int position;
                private int table_idx;
@@ -29,7 +31,7 @@ namespace System.Reflection.Emit {
                        position = pos;
                        attrs = attributes;
                        methodb = mb;
-                       table_idx = mb.get_next_table_index (0x08, true);
+                       table_idx = mb.get_next_table_index (this, 0x08, true);
                }
 
                public virtual int Attributes {
@@ -61,6 +63,21 @@ namespace System.Reflection.Emit {
                }
                
                public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
+                       string attrname = customBuilder.Ctor.ReflectedType.FullName;
+                       if (attrname == "System.Runtime.InteropServices.InAttribute") {
+                               attrs |= ParameterAttributes.In;
+                               return;
+                       } else if (attrname == "System.Runtime.InteropServices.OutAttribute") {
+                               attrs |= ParameterAttributes.Out;
+                               return;
+                       } else if (attrname == "System.Runtime.InteropServices.OptionalAttribute") {
+                               attrs |= ParameterAttributes.Optional;
+                               return;
+                       } else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute") {
+                               marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, true);
+                               /* FIXME: check for errors */
+                               return;
+                       }
                        if (cattrs != null) {
                                CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
                                cattrs.CopyTo (new_array, 0);
@@ -74,13 +91,12 @@ namespace System.Reflection.Emit {
                public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
                        SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
                }
+
                public virtual void SetMarshal( UnmanagedMarshal unmanagedMarshal) {
+                       marshal_info = unmanagedMarshal;
+                       attrs |= ParameterAttributes.HasFieldMarshal;
                }
 
-
-
-
-
        }
 }