2003-11-06 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / ParameterBuilder.cs
index f417c854da5132d25dea8f327dec5f25783f022a..02ba64986cda365a729c9c26feb789c68d7dd09e 100755 (executable)
@@ -14,11 +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;
@@ -28,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 {
@@ -60,16 +63,40 @@ 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);
+                               new_array [cattrs.Length] = customBuilder;
+                               cattrs = new_array;
+                       } else {
+                               cattrs = new CustomAttributeBuilder [1];
+                               cattrs [0] = customBuilder;
+                       }
                }
                public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
+                       SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
                }
+
                public virtual void SetMarshal( UnmanagedMarshal unmanagedMarshal) {
+                       marshal_info = unmanagedMarshal;
+                       attrs |= ParameterAttributes.HasFieldMarshal;
                }
 
-
-
-
-
        }
 }