2005-06-14 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / UnmanagedMarshal.cs
old mode 100755 (executable)
new mode 100644 (file)
index 22627df..d0cff09
@@ -37,6 +37,10 @@ using System;
 
 namespace System.Reflection.Emit {
 
+#if NET_2_0
+       [Obsolete ("An alternate API is available: Emit the MarshalAs custom attribute instead.")]
+       [ComVisible (true)]
+#endif
        [Serializable]
        public sealed class UnmanagedMarshal {
                private int count;
@@ -46,6 +50,8 @@ namespace System.Reflection.Emit {
                string mcookie;
                string marshaltype;
                Type marshaltyperef;
+               private int param_num;
+               private bool has_size;
                
                private UnmanagedMarshal (UnmanagedType maint, int cnt) {
                        count = cnt;
@@ -111,5 +117,31 @@ namespace System.Reflection.Emit {
                        return res;
                }
 
+               // sizeConst and sizeParamIndex can be -1 meaning they are not specified
+               internal static UnmanagedMarshal DefineLPArrayInternal (UnmanagedType elemType, int sizeConst, int sizeParamIndex) {
+                       UnmanagedMarshal res = new UnmanagedMarshal (UnmanagedType.LPArray, elemType);
+                       res.count = sizeConst;
+                       res.param_num = sizeParamIndex;
+                       res.has_size = true;
+
+                       return res;
+               }
+
+               internal MarshalAsAttribute ToMarshalAsAttribute () {
+                       MarshalAsAttribute attr = new MarshalAsAttribute (t);
+                       attr.ArraySubType = tbase;
+                       attr.MarshalCookie = mcookie;
+                       attr.MarshalType = marshaltype;
+                       attr.MarshalTypeRef = marshaltyperef;
+                       if (count == -1)
+                               attr.SizeConst = 0;
+                       else
+                               attr.SizeConst = count;
+                       if (param_num == -1)
+                               attr.SizeParamIndex = 0;
+                       else
+                               attr.SizeParamIndex = (short)param_num;
+                       return attr;
+               }
        }
 }