Merge pull request #3528 from BrzVlad/fix-sgen-check-before-collections
[mono.git] / mcs / class / corlib / System.Reflection.Emit / UnmanagedMarshal.cs
old mode 100755 (executable)
new mode 100644 (file)
index 096fafc..8772be5
 // (C) 2001-2002 Ximian, Inc.  http://www.ximian.com
 //
 
+#if !FULL_AOT_RUNTIME
 using System.Reflection.Emit;
 using System.Runtime.InteropServices;
 using System;
 
 namespace System.Reflection.Emit {
 
+       [Obsolete ("An alternate API is available: Emit the MarshalAs custom attribute instead.")]
+       [ComVisible (true)]
        [Serializable]
+       [StructLayout (LayoutKind.Sequential)]
        public sealed class UnmanagedMarshal {
+#pragma warning disable 169, 414
                private int count;
                private UnmanagedType t;
                private UnmanagedType tbase;
                string guid;
                string mcookie;
                string marshaltype;
-               Type marshaltyperef;
+               internal Type marshaltyperef;
                private int param_num;
                private bool has_size;
+#pragma warning restore 169, 414
                
                private UnmanagedMarshal (UnmanagedType maint, int cnt) {
                        count = cnt;
@@ -62,8 +68,13 @@ namespace System.Reflection.Emit {
                
                public UnmanagedType BaseType {
                        get {
-                               if (t == UnmanagedType.LPArray || t == UnmanagedType.SafeArray)
+                               if (t == UnmanagedType.LPArray)
                                        throw new ArgumentException ();
+
+#if FEATURE_COMINTEROP
+                               if (t == UnmanagedType.SafeArray)
+                                       throw new ArgumentException ();
+#endif
                                return tbase;
                        }
                }
@@ -91,28 +102,27 @@ namespace System.Reflection.Emit {
                public static UnmanagedMarshal DefineLPArray( UnmanagedType elemType) {
                        return new UnmanagedMarshal (UnmanagedType.LPArray, elemType);
                }
-
+#if FEATURE_COMINTEROP
                public static UnmanagedMarshal DefineSafeArray( UnmanagedType elemType) {
                        return new UnmanagedMarshal (UnmanagedType.SafeArray, elemType);
                }
-
+#endif
                public static UnmanagedMarshal DefineUnmanagedMarshal( UnmanagedType unmanagedType) {
                        return new UnmanagedMarshal (unmanagedType, unmanagedType);
                }
-
-               /* this one is missing from the MS implementation */
-               public static UnmanagedMarshal DefineCustom (Type typeref, string cookie, string mtype, Guid id) {
+#if FEATURE_COMINTEROP
+               internal static UnmanagedMarshal DefineCustom (Type typeref, string cookie, string mtype, Guid id) {
                        UnmanagedMarshal res = new UnmanagedMarshal (UnmanagedType.CustomMarshaler, UnmanagedType.CustomMarshaler);
                        res.mcookie = cookie;
                        res.marshaltype = mtype;
                        res.marshaltyperef = typeref;
                        if (id == Guid.Empty)
-                               res.guid = "";
+                               res.guid = String.Empty;
                        else
                                res.guid = id.ToString ();
                        return res;
                }
-
+#endif         
                // 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);
@@ -122,22 +132,6 @@ namespace System.Reflection.Emit {
 
                        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;
-               }
        }
 }
+#endif