From f121eb73d4f268446c047d015303a80b71380b90 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Mon, 15 May 2017 02:23:43 +0200 Subject: [PATCH] [System.Drawing] NS1.6 compatibility: Use GetTypeInfo () where required (#4861) * netstandard1.6 compatibility: Use GetTypeInfo () where required A lot of methods have moved from Type to TypeInfo in netstandard1.6, add calls to GetTypeInfo () where required to support compiling System.Drawing on netstandard1.6 * Add missing using statement --- .../System.Drawing.Printing/MarginsConverter.cs | 2 +- mcs/class/System.Drawing/System.Drawing/ColorConverter.cs | 8 ++++---- .../System.Drawing/System.Drawing/ComIStreamMarshaler.cs | 2 +- mcs/class/System.Drawing/System.Drawing/FontConverter.cs | 2 +- .../System.Drawing/System.Drawing/ImageFormatConverter.cs | 4 ++-- .../System.Drawing/ToolboxBitmapAttribute.cs | 3 ++- mcs/class/System.Drawing/System.Drawing/macFunctions.cs | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/MarginsConverter.cs b/mcs/class/System.Drawing/System.Drawing.Printing/MarginsConverter.cs index 32f21b8bea4..99f194354f6 100644 --- a/mcs/class/System.Drawing/System.Drawing.Printing/MarginsConverter.cs +++ b/mcs/class/System.Drawing/System.Drawing.Printing/MarginsConverter.cs @@ -103,7 +103,7 @@ namespace System.Drawing.Printing { } if (destinationType == typeof (InstanceDescriptor) && value is Margins) { Margins c = (Margins) value; - ConstructorInfo ctor = typeof(Margins).GetConstructor (new Type[] {typeof(int), typeof(int), typeof(int), typeof(int)} ); + ConstructorInfo ctor = typeof(Margins).GetTypeInfo ().GetConstructor (new Type[] {typeof(int), typeof(int), typeof(int), typeof(int)} ); return new InstanceDescriptor (ctor, new object[] {c.Left, c.Right, c.Top, c.Bottom}); } diff --git a/mcs/class/System.Drawing/System.Drawing/ColorConverter.cs b/mcs/class/System.Drawing/System.Drawing/ColorConverter.cs index 2a49f6f945b..e729a035286 100644 --- a/mcs/class/System.Drawing/System.Drawing/ColorConverter.cs +++ b/mcs/class/System.Drawing/System.Drawing/ColorConverter.cs @@ -205,13 +205,13 @@ namespace System.Drawing return sb.ToString (); } else if (destinationType == typeof (InstanceDescriptor)) { if (color.IsEmpty) { - return new InstanceDescriptor (typeof (Color).GetField ("Empty"), null); + return new InstanceDescriptor (typeof (Color).GetTypeInfo ().GetField ("Empty"), null); } else if (color.IsSystemColor) { - return new InstanceDescriptor (typeof (SystemColors).GetProperty (color.Name), null); + return new InstanceDescriptor (typeof (SystemColors).GetTypeInfo ().GetProperty (color.Name), null); } else if (color.IsKnownColor){ - return new InstanceDescriptor (typeof (Color).GetProperty (color.Name), null); + return new InstanceDescriptor (typeof (Color).GetTypeInfo ().GetProperty (color.Name), null); } else { - MethodInfo met = typeof(Color).GetMethod ("FromArgb", new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) } ); + MethodInfo met = typeof(Color).GetTypeInfo ().GetMethod ("FromArgb", new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) } ); return new InstanceDescriptor (met, new object[] {color.A, color.R, color.G, color.B }); } } diff --git a/mcs/class/System.Drawing/System.Drawing/ComIStreamMarshaler.cs b/mcs/class/System.Drawing/System.Drawing/ComIStreamMarshaler.cs index 5064cae15d4..c12a852f04b 100644 --- a/mcs/class/System.Drawing/System.Drawing/ComIStreamMarshaler.cs +++ b/mcs/class/System.Drawing/System.Drawing/ComIStreamMarshaler.cs @@ -105,7 +105,7 @@ namespace System.Drawing private static readonly Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046"); private static readonly Guid IID_IStream = new Guid("0000000C-0000-0000-C000-000000000046"); - private static readonly MethodInfo exceptionGetHResult = typeof(Exception).GetProperty("HResult", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding, null, typeof(int), new Type[] {}, null).GetGetMethod(true); + private static readonly MethodInfo exceptionGetHResult = typeof(Exception).GetTypeInfo ().GetProperty("HResult", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding, null, typeof(int), new Type[] {}, null).GetGetMethod(true); // Keeps delegates alive while they are marshaled private static readonly IStreamVtbl managedVtable; private static IntPtr comVtable; diff --git a/mcs/class/System.Drawing/System.Drawing/FontConverter.cs b/mcs/class/System.Drawing/System.Drawing/FontConverter.cs index 383dee47d52..13f05dd5bc6 100644 --- a/mcs/class/System.Drawing/System.Drawing/FontConverter.cs +++ b/mcs/class/System.Drawing/System.Drawing/FontConverter.cs @@ -114,7 +114,7 @@ namespace System.Drawing if ((destinationType == typeof (InstanceDescriptor)) && (value is Font)) { Font font = (Font) value; - ConstructorInfo met = typeof(Font).GetConstructor (new Type[] {typeof(string), typeof(float), typeof(FontStyle), typeof(GraphicsUnit)}); + ConstructorInfo met = typeof(Font).GetTypeInfo ().GetConstructor (new Type[] {typeof(string), typeof(float), typeof(FontStyle), typeof(GraphicsUnit)}); object[] args = new object[4]; args [0] = font.Name; args [1] = font.Size; diff --git a/mcs/class/System.Drawing/System.Drawing/ImageFormatConverter.cs b/mcs/class/System.Drawing/System.Drawing/ImageFormatConverter.cs index 89f9e2fa0b0..a6195011da3 100644 --- a/mcs/class/System.Drawing/System.Drawing/ImageFormatConverter.cs +++ b/mcs/class/System.Drawing/System.Drawing/ImageFormatConverter.cs @@ -154,9 +154,9 @@ namespace System.Drawing return prop != null ? prop : c.ToString (); } else if (destinationType == typeof (InstanceDescriptor)) { if (prop != null){ - return new InstanceDescriptor (typeof (ImageFormat).GetProperty (prop), null); + return new InstanceDescriptor (typeof (ImageFormat).GetTypeInfo ().GetProperty (prop), null); } else { - ConstructorInfo ctor = typeof(ImageFormat).GetConstructor (new Type[] {typeof(Guid)} ); + ConstructorInfo ctor = typeof(ImageFormat).GetTypeInfo ().GetConstructor (new Type[] {typeof(Guid)} ); return new InstanceDescriptor (ctor, new object[] {c.Guid}); } } diff --git a/mcs/class/System.Drawing/System.Drawing/ToolboxBitmapAttribute.cs b/mcs/class/System.Drawing/System.Drawing/ToolboxBitmapAttribute.cs index 9737b48e1dc..6352155fb96 100644 --- a/mcs/class/System.Drawing/System.Drawing/ToolboxBitmapAttribute.cs +++ b/mcs/class/System.Drawing/System.Drawing/ToolboxBitmapAttribute.cs @@ -33,6 +33,7 @@ // using System; +using System.Reflection; namespace System.Drawing { @@ -116,7 +117,7 @@ namespace System.Drawing imageName = t.Name + ".bmp"; try { - using (System.IO.Stream s = t.Assembly.GetManifestResourceStream (t.Namespace + "." + imageName)){ + using (System.IO.Stream s = t.GetTypeInfo ().Assembly.GetManifestResourceStream (t.Namespace + "." + imageName)){ if (s == null) { return null; } else { diff --git a/mcs/class/System.Drawing/System.Drawing/macFunctions.cs b/mcs/class/System.Drawing/System.Drawing/macFunctions.cs index 7fe2e704a8f..157a8cb398f 100644 --- a/mcs/class/System.Drawing/System.Drawing/macFunctions.cs +++ b/mcs/class/System.Drawing/System.Drawing/macFunctions.cs @@ -52,7 +52,7 @@ namespace System.Drawing { if (String.Equals (asm.GetName ().Name, "System.Windows.Forms")) { Type driver_type = asm.GetType ("System.Windows.Forms.XplatUICarbon"); if (driver_type != null) { - hwnd_delegate = (Delegate) driver_type.GetField ("HwndDelegate", BindingFlags.NonPublic | BindingFlags.Static).GetValue (null); + hwnd_delegate = (Delegate) driver_type.GetTypeInfo() .GetField ("HwndDelegate", BindingFlags.NonPublic | BindingFlags.Static).GetValue (null); } } } -- 2.25.1