Make System.Drawing code compatible with .NET Core (#4548)
authorFrederik Carlier <frederik.carlier@quamotion.mobi>
Fri, 17 Mar 2017 22:30:35 +0000 (23:30 +0100)
committerMarek Safar <marek.safar@gmail.com>
Fri, 17 Mar 2017 22:30:35 +0000 (23:30 +0100)
mcs/class/System.Drawing/System.Drawing.Printing/InvalidPrinterException.cs
mcs/class/System.Drawing/System.Drawing/Bitmap.cs
mcs/class/System.Drawing/System.Drawing/Font.cs
mcs/class/System.Drawing/System.Drawing/Icon.cs
mcs/class/System.Drawing/System.Drawing/Image.cs
mcs/class/referencesource/System/compmod/system/componentmodel/EditorAttribute.cs

index 02a3f27c9a5f9f80c45fdce1cc3c2a442b7b599d..225730863701716bbc2b9273a17a0b333698bee0 100644 (file)
@@ -56,7 +56,7 @@ namespace System.Drawing.Printing {
 
                        base.GetObjectData (info, context);
                }
-               
+
                private static string GetMessage(PrinterSettings settings)
                {
                        if (settings.PrinterName == null || settings.PrinterName == String.Empty)
index ffa825c5f273f0e9208cbb5871b20031094715c6..7a7d8c68952fd7dd9e8cace165984ef9d6096260 100644 (file)
@@ -37,6 +37,7 @@
 
 using System.IO;
 using System.Drawing.Imaging;
+using System.Reflection;
 using System.Runtime.Serialization;
 using System.Runtime.InteropServices;
 using System.ComponentModel;
@@ -132,7 +133,11 @@ namespace System.Drawing
                        if (resource == null)
                                throw new ArgumentException ("resource");
 
-                       Stream s = type.Assembly.GetManifestResourceStream (type, resource);
+                       // For compatibility with the .NET Framework
+                       if (type == null)
+                               throw new NullReferenceException();
+
+                       Stream s = type.GetTypeInfo ().Assembly.GetManifestResourceStream (type, resource);
                        if (s == null) {
                                string msg = Locale.GetText ("Resource '{0}' was not found.", resource);
                                throw new FileNotFoundException (msg);
index 34117a2e1935a713a9a39c23961f96eb595773ca..31861d5123845aa92525989d58a76a31d2fa9a07 100644 (file)
@@ -31,6 +31,7 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Reflection;
 using System.Runtime.Serialization;
 using System.Runtime.InteropServices;
 using System.ComponentModel;
@@ -427,10 +428,7 @@ namespace System.Drawing
                [Browsable(false)]
                public bool IsSystemFont {
                        get {
-                               if (systemFontName == null)
-                                       return false;
-
-                               return StringComparer.InvariantCulture.Compare (systemFontName, string.Empty) != 0;
+                               return !string.IsNullOrEmpty (systemFontName);
                        }
                }
 
@@ -624,7 +622,7 @@ namespace System.Drawing
                        }
 
                        Type st = logFont.GetType ();
-                       if (!st.IsLayoutSequential)
+                       if (!st.GetTypeInfo ().IsLayoutSequential)
                                throw new ArgumentException ("logFont", Locale.GetText ("Layout must be sequential."));
 
                        // note: there is no exception if 'logFont' isn't big enough
index 8352f15c6703c8e6acc3e36bb095edc030b11798..6fe88d5a2e02b682022c7150bc7102f84661a2d1 100644 (file)
@@ -36,6 +36,7 @@ using System.Collections;
 using System.ComponentModel;
 using System.Drawing.Imaging;
 using System.IO;
+using System.Reflection;
 using System.Runtime.Serialization;
 using System.Runtime.InteropServices;
 
@@ -229,7 +230,11 @@ namespace System.Drawing
                        if (resource == null)
                                throw new ArgumentException ("resource");
 
-                       using (Stream s = type.Assembly.GetManifestResourceStream (type, resource)) {
+                       // For compatibility with the .NET Framework
+                       if (type == null)
+                               throw new NullReferenceException();
+
+                       using (Stream s = type.GetTypeInfo ().Assembly.GetManifestResourceStream (type, resource)) {
                                if (s == null) {
                                        string msg = Locale.GetText ("Resource '{0}' was not found.", resource);
                                        throw new FileNotFoundException (msg);
@@ -261,7 +266,7 @@ namespace System.Drawing
 
                internal Icon (string resourceName, bool undisposable)
                {
-                       using (Stream s = typeof (Icon).Assembly.GetManifestResourceStream (resourceName)) {
+                       using (Stream s = typeof (Icon).GetTypeInfo ().Assembly.GetManifestResourceStream (resourceName)) {
                                if (s == null) {
                                        string msg = Locale.GetText ("Resource '{0}' was not found.", resourceName);
                                        throw new FileNotFoundException (msg);
@@ -859,10 +864,10 @@ Console.WriteLine ("\tbih.biClrImportant: {0}", bih.biClrImportant);
                                }
                                
                                imageData [j] = iidata;
-                               bihReader.Close();
+                               bihReader.Dispose ();
                        }                       
 
-                       reader.Close();
+                       reader.Dispose ();
                }
        }
 }
index c5af3c18e1bb7092d4c6c13353113f5a4f7ee898..6bd89918dd66815ca07baedfa7a8a3762c54c53f 100644 (file)
@@ -794,7 +794,7 @@ public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISer
                        Status status = GDIPlus.GdipDisposeImage (nativeObject);
                        // dispose the stream (set under Win32 only if SD owns the stream) and ...
                        if (stream != null) {
-                               stream.Close ();
+                               stream.Dispose ();
                                stream = null;
                        }
                        // ... set nativeObject to null before (possibly) throwing an exception
index c3f493f88dc42349fc0aa8e0b9274ee08b03d2a5..436cc7b930ed01a0c0d17fdaaf0970683c6e0398 100644 (file)
@@ -35,7 +35,7 @@ namespace System.ComponentModel {
         ///    name of the editor.</para>
         /// </devdoc>
         public EditorAttribute(string typeName, string baseTypeName) {
-            string temp = typeName.ToUpper(CultureInfo.InvariantCulture);
+            string temp = typeName.ToUpperInvariant ();
             Debug.Assert(temp.IndexOf(".DLL") == -1, "Came across: " + typeName + " . Please remove the .dll extension");
             this.typeName = typeName;
             this.baseTypeName = baseTypeName;
@@ -45,7 +45,7 @@ namespace System.ComponentModel {
         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class.</para>
         /// </devdoc>
         public EditorAttribute(string typeName, Type baseType) {
-            string temp = typeName.ToUpper(CultureInfo.InvariantCulture);
+            string temp = typeName.ToUpperInvariant ();
             Debug.Assert(temp.IndexOf(".DLL") == -1, "Came across: " + typeName + " . Please remove the .dll extension");
             this.typeName = typeName;
             this.baseTypeName = baseType.AssemblyQualifiedName;