Merge pull request #1659 from alexanderkyte/stringbuilder-referencesource
[mono.git] / mcs / class / corlib / System.Runtime.InteropServices / Marshal.cs
index 48c5db2ea62adb508e662063fc3fca9e4ad276a6..b95713d4e0d013c99a68a7bc78cb4a3587728605 100644 (file)
@@ -187,11 +187,9 @@ namespace System.Runtime.InteropServices
                        throw new NotImplementedException ();
                }
 
-#if NET_4_5
                public static IntPtr CreateAggregatedObject<T> (IntPtr pOuter, T o) {
                        return CreateAggregatedObject (pOuter, (object)o);
                }
-#endif
 
 #if !FULL_AOT_RUNTIME
                public static object CreateWrapperOfType (object o, Type t)
@@ -211,22 +209,18 @@ namespace System.Runtime.InteropServices
                        return ComInteropProxy.GetProxy (co.IUnknown, t).GetTransparentProxy ();
                }
 
-#if NET_4_5
                public static TWrapper CreateWrapperOfType<T, TWrapper> (T o) {
                        return (TWrapper)CreateWrapperOfType ((object)o, typeof (TWrapper));
                }
-#endif
 #endif
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                [ComVisible (true)]
                public extern static void DestroyStructure (IntPtr ptr, Type structuretype);
 
-#if NET_4_5
                public static void DestroyStructure<T> (IntPtr ptr) {
                        DestroyStructure (ptr, typeof (T));
                }
-#endif                 
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public extern static void FreeBSTR (IntPtr ptr);
@@ -347,11 +341,9 @@ namespace System.Runtime.InteropServices
 #endif
                }
 
-#if NET_4_5
                public static IntPtr GetComInterfaceForObject<T, TInterface> (T o) {
                        return GetComInterfaceForObject ((object)o, typeof (T));
                }
-#endif                 
 
                [MonoTODO]
                public static IntPtr GetComInterfaceForObjectInContext (object o, Type t)
@@ -489,11 +481,9 @@ namespace System.Runtime.InteropServices
                        Marshal.StructureToPtr(vt, pDstNativeVariant, false);
                }
 
-#if NET_4_5
                public static void GetNativeVariantForObject<T> (T obj, IntPtr pDstNativeVariant) {
                        GetNativeVariantForObject ((object)obj, pDstNativeVariant);
                }
-#endif
 
 #if !MOBILE
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
@@ -521,12 +511,10 @@ namespace System.Runtime.InteropServices
                        return vt.GetValue();
                }
 
-#if NET_4_5
                public static T GetObjectForNativeVariant<T> (IntPtr pSrcNativeVariant) {
                        Variant vt = (Variant)Marshal.PtrToStructure(pSrcNativeVariant, typeof(Variant));
                        return (T)vt.GetValue();
                }
-#endif
 
                public static object[] GetObjectsForNativeVariants (IntPtr aSrcNativeVariant, int cVars)
                {
@@ -539,7 +527,6 @@ namespace System.Runtime.InteropServices
                        return objects;
                }
 
-#if NET_4_5
                public static T[] GetObjectsForNativeVariants<T> (IntPtr aSrcNativeVariant, int cVars) {
                        if (cVars < 0)
                                throw new ArgumentOutOfRangeException ("cVars", "cVars cannot be a negative number.");
@@ -549,7 +536,6 @@ namespace System.Runtime.InteropServices
                                        i * SizeOf (typeof(Variant))));
                        return objects;
                }
-#endif
 
                [MonoTODO]
                public static int GetStartComSlot (Type t)
@@ -583,12 +569,10 @@ namespace System.Runtime.InteropServices
                        throw new NotImplementedException ();
                }
 
-#if NET_4_5
                public static Type GetTypeFromCLSID (Guid clsid)
                {
                        throw new NotImplementedException ();                   
                }
-#endif
 
 #if !FULL_AOT_RUNTIME
                [Obsolete]
@@ -697,11 +681,9 @@ namespace System.Runtime.InteropServices
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public extern static IntPtr OffsetOf (Type t, string fieldName);
 
-#if NET_4_5
                public static IntPtr OffsetOf<T> (string fieldName) {
                        return OffsetOf (typeof (T), fieldName);
                }
-#endif
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public extern static void Prelink (MethodInfo m);
@@ -751,7 +733,6 @@ namespace System.Runtime.InteropServices
                [ComVisible (true)]
                public extern static object PtrToStructure (IntPtr ptr, Type structureType);
 
-#if NET_4_5
                public static void PtrToStructure<T> (IntPtr ptr, T structure) {
                        PtrToStructure (ptr, (object)structure);
                }
@@ -759,7 +740,6 @@ namespace System.Runtime.InteropServices
                public static T PtrToStructure<T> (IntPtr ptr) {
                        return (T) PtrToStructure (ptr, typeof (T));
                }
-#endif
 
 #if !MOBILE
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
@@ -808,7 +788,7 @@ namespace System.Runtime.InteropServices
                                return *(short*)addr;
 
                        short s;
-                       String.memcpy ((byte*)&s, (byte*)ptr, 2);
+                       Buffer.Memcpy ((byte*)&s, (byte*)ptr, 2);
                        return s;
                }
 
@@ -820,7 +800,7 @@ namespace System.Runtime.InteropServices
                                return *(short*)addr;
 
                        short s;
-                       String.memcpy ((byte*)&s, addr, 2);
+                       Buffer.Memcpy ((byte*)&s, addr, 2);
                        return s;
                }
 
@@ -840,7 +820,7 @@ namespace System.Runtime.InteropServices
                                return *(int*)addr;
 
                        int s;
-                       String.memcpy ((byte*)&s, addr, 4);
+                       Buffer.Memcpy ((byte*)&s, addr, 4);
                        return s;
                }
 
@@ -853,7 +833,7 @@ namespace System.Runtime.InteropServices
                                return *(int*)addr;
                        else {
                                int s;
-                               String.memcpy ((byte*)&s, addr, 4);
+                               Buffer.Memcpy ((byte*)&s, addr, 4);
                                return s;
                        }
                }
@@ -877,7 +857,7 @@ namespace System.Runtime.InteropServices
                                return *(long*)ptr;
 
                        long s;
-                       String.memcpy ((byte*)&s, addr, 8);
+                       Buffer.Memcpy ((byte*)&s, addr, 8);
                        return s;
                }
 
@@ -889,7 +869,7 @@ namespace System.Runtime.InteropServices
                                return *(long*)addr;
                        
                        long s;
-                       String.memcpy ((byte*)&s, addr, 8);
+                       Buffer.Memcpy ((byte*)&s, addr, 8);
                        return s;
                }
 
@@ -987,7 +967,6 @@ namespace System.Runtime.InteropServices
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public extern static int SizeOf (Type t);
 
-#if NET_4_5
                public static int SizeOf<T> () {
                        return SizeOf (typeof (T));
                }
@@ -995,7 +974,6 @@ namespace System.Runtime.InteropServices
                public static int SizeOf<T> (T structure) {
                        return SizeOf (structure.GetType ());
                }
-#endif
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public extern static IntPtr StringToBSTR (string s);
@@ -1143,11 +1121,9 @@ namespace System.Runtime.InteropServices
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public extern static void StructureToPtr (object structure, IntPtr ptr, bool fDeleteOld);
 
-#if NET_4_5
                public static void StructureToPtr<T> (T structure, IntPtr ptr, bool fDeleteOld) {
                        StructureToPtr ((object)structure, ptr, fDeleteOld);
                }
-#endif
 
                public static void ThrowExceptionForHR (int errorCode) {
                        Exception ex = GetExceptionForHR (errorCode);
@@ -1164,11 +1140,9 @@ namespace System.Runtime.InteropServices
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public extern static IntPtr UnsafeAddrOfPinnedArrayElement (Array arr, int index);
 
-#if NET_4_5
                public static IntPtr UnsafeAddrOfPinnedArrayElement<T> (T[] arr, int index) {
                        return UnsafeAddrOfPinnedArrayElement ((Array)arr, index);
                }
-#endif
 
                public static void WriteByte (IntPtr ptr, byte val)
                {
@@ -1197,7 +1171,7 @@ namespace System.Runtime.InteropServices
                        if (((uint)addr & 1) == 0)
                                *(short*)addr = val;
                        else
-                               String.memcpy (addr, (byte*)&val, 2);
+                               Buffer.Memcpy (addr, (byte*)&val, 2);
                }
 
                public static unsafe void WriteInt16 (IntPtr ptr, int ofs, short val)
@@ -1207,7 +1181,7 @@ namespace System.Runtime.InteropServices
                        if (((uint)addr & 1) == 0)
                                *(short*)addr = val;
                        else {
-                               String.memcpy (addr, (byte*)&val, 2);
+                               Buffer.Memcpy (addr, (byte*)&val, 2);
                        }
                }
 
@@ -1241,7 +1215,7 @@ namespace System.Runtime.InteropServices
                        if (((uint)addr & 3) == 0) 
                                *(int*)addr = val;
                        else {
-                               String.memcpy (addr, (byte*)&val, 4);
+                               Buffer.Memcpy (addr, (byte*)&val, 4);
                        }
                }
 
@@ -1252,7 +1226,7 @@ namespace System.Runtime.InteropServices
                        if (((uint)addr & 3) == 0) 
                                *(int*)addr = val;
                        else {
-                               String.memcpy (addr, (byte*)&val, 4);
+                               Buffer.Memcpy (addr, (byte*)&val, 4);
                        }
                }
 
@@ -1272,7 +1246,7 @@ namespace System.Runtime.InteropServices
                        if (((uint)addr & 7) == 0) 
                                *(long*)addr = val;
                        else 
-                               String.memcpy (addr, (byte*)&val, 8);
+                               Buffer.Memcpy (addr, (byte*)&val, 8);
                }
 
                public static unsafe void WriteInt64 (IntPtr ptr, int ofs, long val)
@@ -1284,7 +1258,7 @@ namespace System.Runtime.InteropServices
                        if (((uint)addr & 7) == 0) 
                                *(long*)addr = val;
                        else 
-                               String.memcpy (addr, (byte*)&val, 8);
+                               Buffer.Memcpy (addr, (byte*)&val, 8);
                }
 
                [MonoTODO]
@@ -1585,6 +1559,7 @@ namespace System.Runtime.InteropServices
 
                public static Exception GetExceptionForHR (int errorCode, IntPtr errorInfo)
                {
+#if !MOBILE
                        IErrorInfo info = null;
                        if (errorInfo != (IntPtr)(-1)) {
                                if (errorInfo == IntPtr.Zero) {
@@ -1618,6 +1593,9 @@ namespace System.Runtime.InteropServices
                                }
                        }
                        return e;
+#else
+                       return ConvertHrToException (errorCode);
+#endif
                }
 
 #if !FULL_AOT_RUNTIME
@@ -1645,11 +1623,9 @@ namespace System.Runtime.InteropServices
                        return GetDelegateForFunctionPointerInternal (ptr, t);
                }
 
-#if NET_4_5
                public static TDelegate GetDelegateForFunctionPointer<TDelegate> (IntPtr ptr) {
                        return (TDelegate) (object) GetDelegateForFunctionPointer (ptr, typeof (TDelegate));
                }
-#endif
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private static extern IntPtr GetFunctionPointerForDelegateInternal (Delegate d);
@@ -1662,13 +1638,11 @@ namespace System.Runtime.InteropServices
                        return GetFunctionPointerForDelegateInternal (d);
                }
 
-#if NET_4_5
                public static IntPtr GetFunctionPointerForDelegate<TDelegate> (TDelegate d) {
                        if (d == null)
                                throw new ArgumentNullException ("d");
                        
                        return GetFunctionPointerForDelegateInternal ((Delegate)(object)d);
                }
-#endif
        }
 }