[System.Drawing] NS1.6 compatibility: Use GetTypeInfo () where required (#4861)
[mono.git] / mcs / class / System.Drawing / System.Drawing / ColorConverter.cs
index dffdb66b6e2027f941d5b8c20bf0295af6e58837..e729a035286833480690f8268f8112976620fb50 100644 (file)
@@ -6,7 +6,7 @@
 //     Ravindra (rkumar@novell.com)
 //
 // Copyright (C) 2002 Ximian, Inc.  http://www.ximian.com
-// Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004,2006,2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -176,47 +176,44 @@ namespace System.Drawing
                                                  object value,
                                                  Type destinationType)
                {
-                       if ((destinationType == typeof (string)) && (value is Color)) {
+                       if (value is Color) {
                                Color color = (Color) value;
+                               if (destinationType == typeof (string)) {
+                                       if (color == Color.Empty)
+                                               return string.Empty;
 
-                               if (color == Color.Empty) {
-                                       return string.Empty;
-                               }
-
-                               if (color.IsKnownColor || color.IsNamedColor)
-                                       return color.Name;
+                                       if (color.IsKnownColor || color.IsNamedColor)
+                                               return color.Name;
 
-                               String numSeparator = culture.TextInfo.ListSeparator;
+                                       String numSeparator = culture.TextInfo.ListSeparator;
 
-                               StringBuilder sb = new StringBuilder ();
-                               if (color.A != 255) {
-                                       sb.Append (color.A);
+                                       StringBuilder sb = new StringBuilder ();
+                                       if (color.A != 255) {
+                                               sb.Append (color.A);
+                                               sb.Append (numSeparator);
+                                               sb.Append (" ");
+                                       }
+                                       sb.Append (color.R);
                                        sb.Append (numSeparator);
                                        sb.Append (" ");
-                               }
-                               sb.Append (color.R);
-                               sb.Append (numSeparator);
-                               sb.Append (" ");
 
-                               sb.Append (color.G);
-                               sb.Append (numSeparator);
-                               sb.Append (" ");
+                                       sb.Append (color.G);
+                                       sb.Append (numSeparator);
+                                       sb.Append (" ");
 
-                               sb.Append (color.B);
-                               return sb.ToString ();
-                       }
-                       
-                       if (destinationType == typeof (InstanceDescriptor) && value is Color) {
-                               Color c = (Color)value;
-                               if (c.IsEmpty) {
-                                       return new InstanceDescriptor (typeof (Color).GetField ("Empty"), null);
-                               } else if (c.IsSystemColor) {
-                                       return new InstanceDescriptor (typeof (SystemColors).GetProperty (c.Name), null);
-                               } else if (c.IsKnownColor){
-                                       return new InstanceDescriptor (typeof (Color).GetProperty (c.Name), null);
-                               } else {
-                                       MethodInfo met = typeof(Color).GetMethod ("FromArgb", new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) } );
-                                       return new InstanceDescriptor (met, new object[] {c.A, c.R, c.G, c.B });
+                                       sb.Append (color.B);
+                                       return sb.ToString ();
+                               } else if (destinationType == typeof (InstanceDescriptor)) {
+                                       if (color.IsEmpty) {
+                                               return new InstanceDescriptor (typeof (Color).GetTypeInfo ().GetField ("Empty"), null);
+                                       } else if (color.IsSystemColor) {
+                                               return new InstanceDescriptor (typeof (SystemColors).GetTypeInfo ().GetProperty (color.Name), null);
+                                       } else if (color.IsKnownColor){
+                                               return new InstanceDescriptor (typeof (Color).GetTypeInfo ().GetProperty (color.Name), null);
+                                       } else {
+                                               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 });
+                                       }
                                }
                        }
 
@@ -228,15 +225,10 @@ namespace System.Drawing
                        lock (creatingCached) {
                                if (cached != null)
                                        return cached;
-#if TARGET_JVM
-                               Color [] colors = new Color [KnownColors.Values.Length - 1];
-                               Array.Copy (KnownColors.Values, 1, colors, 0, colors.Length);
-#else
                                Array colors = Array.CreateInstance (typeof (Color), KnownColors.ArgbValues.Length - 1);
                                for (int i=1; i < KnownColors.ArgbValues.Length; i++) {
                                        colors.SetValue (KnownColors.FromKnownColor ((KnownColor)i), i - 1);
                                }
-#endif
 
                                Array.Sort (colors, 0, colors.Length, new CompareColors ());
                                cached = new StandardValuesCollection (colors);