From c7093a57a3bc813f76ec90adc9454750b1447733 Mon Sep 17 00:00:00 2001 From: Eric Mellino Date: Mon, 31 Jul 2017 12:40:00 -0700 Subject: [PATCH 1/2] Add a netcoreapp2.0 configuration for System.Drawing.Common. --- external/dir.proj | 1 + external/netcoreapp/Configurations.props | 8 ++ external/netcoreapp/netcoreapp.depproj | 29 +++++ .../System/Drawing/ColorUtil.netcoreapp20.cs | 98 +++++++++++++++ .../System/Drawing/ColorUtil.netcoreapp21.cs | 15 +++ .../src/System/Drawing/KnownColor.cs | 0 .../src/System/Drawing/KnownColorTable.cs | 4 +- .../System.Drawing.Common.sln | 16 +-- .../ref/Configurations.props | 2 +- .../ref/System.Drawing.Common.csproj | 20 +-- .../src/Configurations.props | 4 +- .../src/System.Drawing.Common.csproj | 23 +++- .../src/System/Drawing/BitmapSelector.cs | 18 +-- .../src/System/Drawing/ColorTranslator.cs | 118 +++++++++--------- .../src/System/Drawing/Font.cs | 4 +- .../src/System/Drawing/SystemBrushes.cs | 2 +- .../src/System/Drawing/SystemColors.cs | 84 ++++++------- .../src/System/Drawing/SystemPens.cs | 2 +- .../Unix/System.Drawing/ColorTranslator.cs | 2 +- .../src/Unix/System.Drawing/KnownColors.cs | 2 +- .../src/Unix/System.Drawing/SystemPens.cs | 2 +- .../src/misc/DpiHelper.cs | 15 +-- .../src/misc/InvalidEnumArgumentException.cs | 63 ++++++++++ .../tests/Drawing2D/GraphicsPathTests.cs | 2 +- .../Drawing2D/LinearGradientBrushTests.cs | 8 +- .../tests/Drawing2D/PathGradientBrushTests.cs | 6 +- .../tests/GraphicsTests.cs | 16 +-- .../tests/Imaging/BitmapDataTests.cs | 2 +- src/System.Drawing.Common/tests/PenTests.cs | 12 +- .../tests/Printing/PrinterResolutionTests.cs | 2 +- .../tests/StringFormatTests.cs | 8 +- .../tests/TextureBrushTests.cs | 8 +- .../src/System.Drawing.Primitives.csproj | 7 +- 33 files changed, 406 insertions(+), 197 deletions(-) create mode 100644 external/netcoreapp/Configurations.props create mode 100644 external/netcoreapp/netcoreapp.depproj create mode 100644 src/Common/src/System/Drawing/ColorUtil.netcoreapp20.cs create mode 100644 src/Common/src/System/Drawing/ColorUtil.netcoreapp21.cs rename src/{System.Drawing.Primitives => Common}/src/System/Drawing/KnownColor.cs (100%) create mode 100644 src/System.Drawing.Common/src/misc/InvalidEnumArgumentException.cs diff --git a/external/dir.proj b/external/dir.proj index d3d7fd8769b3..55f28134c57b 100644 --- a/external/dir.proj +++ b/external/dir.proj @@ -7,6 +7,7 @@ + diff --git a/external/netcoreapp/Configurations.props b/external/netcoreapp/Configurations.props new file mode 100644 index 000000000000..7b75ea543a2e --- /dev/null +++ b/external/netcoreapp/Configurations.props @@ -0,0 +1,8 @@ + + + + + netcoreapp2.0 + + + \ No newline at end of file diff --git a/external/netcoreapp/netcoreapp.depproj b/external/netcoreapp/netcoreapp.depproj new file mode 100644 index 000000000000..c52459d9fe0b --- /dev/null +++ b/external/netcoreapp/netcoreapp.depproj @@ -0,0 +1,29 @@ + + + + + true + Reference + 2.0.0-preview2-25407-01 + netcoreapp2.0 + + + + + $(NETCoreAppPackageVersion) + + + + + + + $(RefPath) + + + + $(TestHostRootPath) + + + + + diff --git a/src/Common/src/System/Drawing/ColorUtil.netcoreapp20.cs b/src/Common/src/System/Drawing/ColorUtil.netcoreapp20.cs new file mode 100644 index 000000000000..259c9ae52f56 --- /dev/null +++ b/src/Common/src/System/Drawing/ColorUtil.netcoreapp20.cs @@ -0,0 +1,98 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics; +using System.Reflection; + +namespace System.Drawing +{ + // System.Drawing.Common uses several members on System.Drawing.Common which are implemented in .NET Core 2.0, but + // not exposed. This is a helper class which allows System.Drawing.Common to access those members through reflection. + internal static class ColorUtil + { + private const short StateKnownColorValid = 0x0001; + private const short StateNameValid = 0x0008; + private const long NotDefinedValue = 0; + + private static readonly ConstructorInfo s_ctorKnownColor; // internal Color(KnownColor knownColor) + private static readonly ConstructorInfo s_ctorAllValues; // private Color(long value, short state, string name, KnownColor knownColor) + private static readonly FieldInfo s_fieldKnownColor; // private readonly short knownColor + private static readonly FieldInfo s_fieldState; // private readonly short state + + static ColorUtil() + { + Type colorType = typeof(Color); + Type knownColorType = colorType.Assembly.GetType("System.Drawing.KnownColor", true); + Debug.Assert(knownColorType != null); + const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; + s_ctorKnownColor = colorType.GetConstructor(bindingFlags, null, new Type[] { knownColorType }, null); + Debug.Assert(s_ctorKnownColor != null); + + s_ctorAllValues = colorType.GetConstructor(bindingFlags, null, new Type[] { typeof(long), typeof(short), typeof(string), knownColorType }, null); + Debug.Assert(s_ctorAllValues != null); + + s_fieldKnownColor = colorType.GetField("knownColor", bindingFlags); + Debug.Assert(s_fieldKnownColor != null); + + s_fieldState = colorType.GetField("state", bindingFlags); + Debug.Assert(s_fieldState != null); + } + + public static Color FromKnownColor(KnownColor color) + { + var value = (int)color; + if (value < (int)KnownColor.ActiveBorder || value > (int)KnownColor.MenuHighlight) + { + return FromName(color.ToString()); + } + + return (Color)s_ctorKnownColor.Invoke(new object[] { value }); + } + + public static Color FromName(string name) + { + // try to get a known color first + Color color; + if (ColorTable.TryGetNamedColor(name, out color)) + { + return color; + } + // otherwise treat it as a named color + return (Color)s_ctorAllValues.Invoke(new object[] { NotDefinedValue, StateNameValid, name, 0 }); + } + + public static bool IsSystemColor(this Color color) + { + short knownColor = GetKnownColor(color); + return GetIsKnownColor(color) && ((((KnownColor)knownColor) <= KnownColor.WindowText) || (((KnownColor)knownColor) > KnownColor.YellowGreen)); + } + + public static short GetKnownColor(this Color color) + { + return (short)s_fieldKnownColor.GetValue(color); + } + + public static short GetState(this Color color) + { + return (short)s_fieldState.GetValue(color); + } + + public static bool GetIsSystemColor(this Color color) + { + short knownColor = color.GetKnownColor(); + return GetIsKnownColor(color) && ((((KnownColor)knownColor) <= KnownColor.WindowText) || (((KnownColor)knownColor) > KnownColor.YellowGreen)); + } + + public static bool GetIsKnownColor(this Color color) + { + short state = GetState(color); + return ((state & StateKnownColorValid) != 0); + } + + public static KnownColor ToKnownColor(this Color c) + { + return (KnownColor)GetKnownColor(c); + } + } +} \ No newline at end of file diff --git a/src/Common/src/System/Drawing/ColorUtil.netcoreapp21.cs b/src/Common/src/System/Drawing/ColorUtil.netcoreapp21.cs new file mode 100644 index 000000000000..e65f14c839a8 --- /dev/null +++ b/src/Common/src/System/Drawing/ColorUtil.netcoreapp21.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics; +using System.Reflection; + +namespace System.Drawing +{ + internal static class ColorUtil + { + public static Color FromKnownColor(KnownColor color) => Color.FromKnownColor(color); + public static bool IsSystemColor(this Color color) => color.IsSystemColor; + } +} \ No newline at end of file diff --git a/src/System.Drawing.Primitives/src/System/Drawing/KnownColor.cs b/src/Common/src/System/Drawing/KnownColor.cs similarity index 100% rename from src/System.Drawing.Primitives/src/System/Drawing/KnownColor.cs rename to src/Common/src/System/Drawing/KnownColor.cs diff --git a/src/Common/src/System/Drawing/KnownColorTable.cs b/src/Common/src/System/Drawing/KnownColorTable.cs index 511a1770b844..fe37dc540857 100644 --- a/src/Common/src/System/Drawing/KnownColorTable.cs +++ b/src/Common/src/System/Drawing/KnownColorTable.cs @@ -35,8 +35,8 @@ public static Color ArgbToKnownColor(int targetARGB) int argb = s_colorTable[index]; if (argb == targetARGB) { - Color color = Color.FromKnownColor((KnownColor)index); - if (!color.IsSystemColor) + Color color = ColorUtil.FromKnownColor((KnownColor)index); + if (!ColorUtil.IsSystemColor(color)) return color; } } diff --git a/src/System.Drawing.Common/System.Drawing.Common.sln b/src/System.Drawing.Common/System.Drawing.Common.sln index de11d3e8e7e9..3cba2fba5f8a 100644 --- a/src/System.Drawing.Common/System.Drawing.Common.sln +++ b/src/System.Drawing.Common/System.Drawing.Common.sln @@ -30,14 +30,14 @@ Global {4B93E684-0630-45F4-8F63-6C7788C9892F}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU {4B93E684-0630-45F4-8F63-6C7788C9892F}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU {4B93E684-0630-45F4-8F63-6C7788C9892F}.Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU - {191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Debug|Any CPU.ActiveCfg = netcoreapp-Unix-Debug|Any CPU - {191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Debug|Any CPU.Build.0 = netcoreapp-Unix-Debug|Any CPU - {191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU - {191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU - {D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU - {D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU - {D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU - {D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU + {191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Debug|Any CPU.ActiveCfg = netcoreapp2.0-Windows_NT-Debug|Any CPU + {191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Debug|Any CPU.Build.0 = netcoreapp2.0-Windows_NT-Debug|Any CPU + {191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Release|Any CPU.ActiveCfg = netcoreapp2.0-Windows_NT-Release|Any CPU + {191B3618-FECD-4ABD-9D6B-5AC90DC33621}.Release|Any CPU.Build.0 = netcoreapp2.0-Windows_NT-Release|Any CPU + {D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Debug|Any CPU.ActiveCfg = netcoreapp2.0-Debug|Any CPU + {D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Debug|Any CPU.Build.0 = netcoreapp2.0-Debug|Any CPU + {D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Release|Any CPU.ActiveCfg = netcoreapp2.0-Release|Any CPU + {D7AEA698-275D-441F-B7A7-8491D1F0EFF0}.Release|Any CPU.Build.0 = netcoreapp2.0-Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/System.Drawing.Common/ref/Configurations.props b/src/System.Drawing.Common/ref/Configurations.props index 2845c11c541d..01894f79b923 100644 --- a/src/System.Drawing.Common/ref/Configurations.props +++ b/src/System.Drawing.Common/ref/Configurations.props @@ -2,7 +2,7 @@ - netcoreapp; + netcoreapp2.0; \ No newline at end of file diff --git a/src/System.Drawing.Common/ref/System.Drawing.Common.csproj b/src/System.Drawing.Common/ref/System.Drawing.Common.csproj index 4987e8df375c..d8daf77d7975 100644 --- a/src/System.Drawing.Common/ref/System.Drawing.Common.csproj +++ b/src/System.Drawing.Common/ref/System.Drawing.Common.csproj @@ -4,20 +4,20 @@ {D7AEA698-275D-441F-B7A7-8491D1F0EFF0} - - + + - - - - - - - - + + + + + + + + diff --git a/src/System.Drawing.Common/src/Configurations.props b/src/System.Drawing.Common/src/Configurations.props index e75400d142ff..85b3fdbbf8b6 100644 --- a/src/System.Drawing.Common/src/Configurations.props +++ b/src/System.Drawing.Common/src/Configurations.props @@ -2,8 +2,8 @@ - netcoreapp-Windows_NT; - netcoreapp-Unix; + netcoreapp2.0-Windows_NT; + netcoreapp2.0-Unix; diff --git a/src/System.Drawing.Common/src/System.Drawing.Common.csproj b/src/System.Drawing.Common/src/System.Drawing.Common.csproj index b3d9253557ba..5a2afcdcc8b4 100644 --- a/src/System.Drawing.Common/src/System.Drawing.Common.csproj +++ b/src/System.Drawing.Common/src/System.Drawing.Common.csproj @@ -12,16 +12,15 @@ $(DefineConstants);FEATURE_WINDOWS_SYSTEM_COLORS $(DefineConstants);CORECLR;NETCORE - - - - + + + + - @@ -41,6 +40,7 @@ + @@ -166,6 +166,12 @@ System\Drawing\ColorTable.cs + + System\Drawing\ColorUtil.netcoreapp20.cs + + + System\Drawing\KnownColor.cs + System\Drawing\KnownColorTable.cs @@ -212,7 +218,9 @@ - + + Component + @@ -241,6 +249,9 @@ + + Common\System\Numerics\Hashing\HashHelpers.cs + Common\Interop\Windows\Interop.Libraries.cs diff --git a/src/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs b/src/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs index d965609a91c6..303174d8f00c 100644 --- a/src/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs +++ b/src/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs @@ -4,8 +4,6 @@ namespace System.Drawing { - using System.Configuration; - using System.Drawing.Configuration; using System.IO; using System.Reflection; @@ -27,19 +25,9 @@ internal static string Suffix { get { - if (s_suffix == null) - { - s_suffix = string.Empty; - var section = ConfigurationManager.GetSection("system.drawing") as SystemDrawingSection; - if (section != null) - { - var value = section.BitmapSuffix; - if (value != null && value is string) - { - s_suffix = (string)value; - } - } - } + // NOTE: This value is read from the "SystemDrawingSection" of the ConfigurationManager on + // the .NET Framework. To avoid pulling in a direct dependency to that assembly, we are not + // reading the value in this implementation. return s_suffix; } set diff --git a/src/System.Drawing.Common/src/System/Drawing/ColorTranslator.cs b/src/System.Drawing.Common/src/System/Drawing/ColorTranslator.cs index 6b17bd0696ad..4c9bd748513c 100644 --- a/src/System.Drawing.Common/src/System/Drawing/ColorTranslator.cs +++ b/src/System.Drawing.Common/src/System/Drawing/ColorTranslator.cs @@ -36,7 +36,7 @@ public static int ToOle(Color c) // We must never have another method called ToOle() with a different signature. // This is so that we can push into the runtime a custom marshaller for OLE_COLOR to Color. - if (c.IsKnownColor) + if (ColorUtil.GetIsKnownColor(c)) { switch (c.ToKnownColor()) { @@ -125,65 +125,65 @@ public static Color FromOle(int oleColor) switch (oleColor) { case unchecked((int)0x8000000A): - return Color.FromKnownColor(KnownColor.ActiveBorder); + return ColorUtil.FromKnownColor(KnownColor.ActiveBorder); case unchecked((int)0x80000002): - return Color.FromKnownColor(KnownColor.ActiveCaption); + return ColorUtil.FromKnownColor(KnownColor.ActiveCaption); case unchecked((int)0x80000009): - return Color.FromKnownColor(KnownColor.ActiveCaptionText); + return ColorUtil.FromKnownColor(KnownColor.ActiveCaptionText); case unchecked((int)0x8000000C): - return Color.FromKnownColor(KnownColor.AppWorkspace); + return ColorUtil.FromKnownColor(KnownColor.AppWorkspace); case unchecked((int)0x8000000F): - return Color.FromKnownColor(KnownColor.Control); + return ColorUtil.FromKnownColor(KnownColor.Control); case unchecked((int)0x80000010): - return Color.FromKnownColor(KnownColor.ControlDark); + return ColorUtil.FromKnownColor(KnownColor.ControlDark); case unchecked((int)0x80000015): - return Color.FromKnownColor(KnownColor.ControlDarkDark); + return ColorUtil.FromKnownColor(KnownColor.ControlDarkDark); case unchecked((int)0x80000016): - return Color.FromKnownColor(KnownColor.ControlLight); + return ColorUtil.FromKnownColor(KnownColor.ControlLight); case unchecked((int)0x80000014): - return Color.FromKnownColor(KnownColor.ControlLightLight); + return ColorUtil.FromKnownColor(KnownColor.ControlLightLight); case unchecked((int)0x80000012): - return Color.FromKnownColor(KnownColor.ControlText); + return ColorUtil.FromKnownColor(KnownColor.ControlText); case unchecked((int)0x80000001): - return Color.FromKnownColor(KnownColor.Desktop); + return ColorUtil.FromKnownColor(KnownColor.Desktop); case unchecked((int)0x8000001B): - return Color.FromKnownColor(KnownColor.GradientActiveCaption); + return ColorUtil.FromKnownColor(KnownColor.GradientActiveCaption); case unchecked((int)0x8000001C): - return Color.FromKnownColor(KnownColor.GradientInactiveCaption); + return ColorUtil.FromKnownColor(KnownColor.GradientInactiveCaption); case unchecked((int)0x80000011): - return Color.FromKnownColor(KnownColor.GrayText); + return ColorUtil.FromKnownColor(KnownColor.GrayText); case unchecked((int)0x8000000D): - return Color.FromKnownColor(KnownColor.Highlight); + return ColorUtil.FromKnownColor(KnownColor.Highlight); case unchecked((int)0x8000000E): - return Color.FromKnownColor(KnownColor.HighlightText); + return ColorUtil.FromKnownColor(KnownColor.HighlightText); case unchecked((int)0x8000001A): - return Color.FromKnownColor(KnownColor.HotTrack); + return ColorUtil.FromKnownColor(KnownColor.HotTrack); case unchecked((int)0x8000000B): - return Color.FromKnownColor(KnownColor.InactiveBorder); + return ColorUtil.FromKnownColor(KnownColor.InactiveBorder); case unchecked((int)0x80000003): - return Color.FromKnownColor(KnownColor.InactiveCaption); + return ColorUtil.FromKnownColor(KnownColor.InactiveCaption); case unchecked((int)0x80000013): - return Color.FromKnownColor(KnownColor.InactiveCaptionText); + return ColorUtil.FromKnownColor(KnownColor.InactiveCaptionText); case unchecked((int)0x80000018): - return Color.FromKnownColor(KnownColor.Info); + return ColorUtil.FromKnownColor(KnownColor.Info); case unchecked((int)0x80000017): - return Color.FromKnownColor(KnownColor.InfoText); + return ColorUtil.FromKnownColor(KnownColor.InfoText); case unchecked((int)0x80000004): - return Color.FromKnownColor(KnownColor.Menu); + return ColorUtil.FromKnownColor(KnownColor.Menu); case unchecked((int)0x8000001E): - return Color.FromKnownColor(KnownColor.MenuBar); + return ColorUtil.FromKnownColor(KnownColor.MenuBar); case unchecked((int)0x8000001D): - return Color.FromKnownColor(KnownColor.MenuHighlight); + return ColorUtil.FromKnownColor(KnownColor.MenuHighlight); case unchecked((int)0x80000007): - return Color.FromKnownColor(KnownColor.MenuText); + return ColorUtil.FromKnownColor(KnownColor.MenuText); case unchecked((int)0x80000000): - return Color.FromKnownColor(KnownColor.ScrollBar); + return ColorUtil.FromKnownColor(KnownColor.ScrollBar); case unchecked((int)0x80000005): - return Color.FromKnownColor(KnownColor.Window); + return ColorUtil.FromKnownColor(KnownColor.Window); case unchecked((int)0x80000006): - return Color.FromKnownColor(KnownColor.WindowFrame); + return ColorUtil.FromKnownColor(KnownColor.WindowFrame); case unchecked((int)0x80000008): - return Color.FromKnownColor(KnownColor.WindowText); + return ColorUtil.FromKnownColor(KnownColor.WindowText); } Color color = Color.FromArgb((byte)((oleColor >> Win32RedShift) & 0xFF), @@ -274,7 +274,7 @@ public static string ToHtml(Color c) if (c.IsEmpty) return colorString; - if (c.IsSystemColor) + if (ColorUtil.IsSystemColor(c)) { switch (c.ToKnownColor()) { @@ -385,33 +385,33 @@ public static string ToHtml(Color c) private static void InitializeHtmlSysColorTable() { s_htmlSysColorTable = new Hashtable(26); - s_htmlSysColorTable["activeborder"] = Color.FromKnownColor(KnownColor.ActiveBorder); - s_htmlSysColorTable["activecaption"] = Color.FromKnownColor(KnownColor.ActiveCaption); - s_htmlSysColorTable["appworkspace"] = Color.FromKnownColor(KnownColor.AppWorkspace); - s_htmlSysColorTable["background"] = Color.FromKnownColor(KnownColor.Desktop); - s_htmlSysColorTable["buttonface"] = Color.FromKnownColor(KnownColor.Control); - s_htmlSysColorTable["buttonhighlight"] = Color.FromKnownColor(KnownColor.ControlLightLight); - s_htmlSysColorTable["buttonshadow"] = Color.FromKnownColor(KnownColor.ControlDark); - s_htmlSysColorTable["buttontext"] = Color.FromKnownColor(KnownColor.ControlText); - s_htmlSysColorTable["captiontext"] = Color.FromKnownColor(KnownColor.ActiveCaptionText); - s_htmlSysColorTable["graytext"] = Color.FromKnownColor(KnownColor.GrayText); - s_htmlSysColorTable["highlight"] = Color.FromKnownColor(KnownColor.Highlight); - s_htmlSysColorTable["highlighttext"] = Color.FromKnownColor(KnownColor.HighlightText); - s_htmlSysColorTable["inactiveborder"] = Color.FromKnownColor(KnownColor.InactiveBorder); - s_htmlSysColorTable["inactivecaption"] = Color.FromKnownColor(KnownColor.InactiveCaption); - s_htmlSysColorTable["inactivecaptiontext"] = Color.FromKnownColor(KnownColor.InactiveCaptionText); - s_htmlSysColorTable["infobackground"] = Color.FromKnownColor(KnownColor.Info); - s_htmlSysColorTable["infotext"] = Color.FromKnownColor(KnownColor.InfoText); - s_htmlSysColorTable["menu"] = Color.FromKnownColor(KnownColor.Menu); - s_htmlSysColorTable["menutext"] = Color.FromKnownColor(KnownColor.MenuText); - s_htmlSysColorTable["scrollbar"] = Color.FromKnownColor(KnownColor.ScrollBar); - s_htmlSysColorTable["threeddarkshadow"] = Color.FromKnownColor(KnownColor.ControlDarkDark); - s_htmlSysColorTable["threedface"] = Color.FromKnownColor(KnownColor.Control); - s_htmlSysColorTable["threedhighlight"] = Color.FromKnownColor(KnownColor.ControlLight); - s_htmlSysColorTable["threedlightshadow"] = Color.FromKnownColor(KnownColor.ControlLightLight); - s_htmlSysColorTable["window"] = Color.FromKnownColor(KnownColor.Window); - s_htmlSysColorTable["windowframe"] = Color.FromKnownColor(KnownColor.WindowFrame); - s_htmlSysColorTable["windowtext"] = Color.FromKnownColor(KnownColor.WindowText); + s_htmlSysColorTable["activeborder"] = ColorUtil.FromKnownColor(KnownColor.ActiveBorder); + s_htmlSysColorTable["activecaption"] = ColorUtil.FromKnownColor(KnownColor.ActiveCaption); + s_htmlSysColorTable["appworkspace"] = ColorUtil.FromKnownColor(KnownColor.AppWorkspace); + s_htmlSysColorTable["background"] = ColorUtil.FromKnownColor(KnownColor.Desktop); + s_htmlSysColorTable["buttonface"] = ColorUtil.FromKnownColor(KnownColor.Control); + s_htmlSysColorTable["buttonhighlight"] = ColorUtil.FromKnownColor(KnownColor.ControlLightLight); + s_htmlSysColorTable["buttonshadow"] = ColorUtil.FromKnownColor(KnownColor.ControlDark); + s_htmlSysColorTable["buttontext"] = ColorUtil.FromKnownColor(KnownColor.ControlText); + s_htmlSysColorTable["captiontext"] = ColorUtil.FromKnownColor(KnownColor.ActiveCaptionText); + s_htmlSysColorTable["graytext"] = ColorUtil.FromKnownColor(KnownColor.GrayText); + s_htmlSysColorTable["highlight"] = ColorUtil.FromKnownColor(KnownColor.Highlight); + s_htmlSysColorTable["highlighttext"] = ColorUtil.FromKnownColor(KnownColor.HighlightText); + s_htmlSysColorTable["inactiveborder"] = ColorUtil.FromKnownColor(KnownColor.InactiveBorder); + s_htmlSysColorTable["inactivecaption"] = ColorUtil.FromKnownColor(KnownColor.InactiveCaption); + s_htmlSysColorTable["inactivecaptiontext"] = ColorUtil.FromKnownColor(KnownColor.InactiveCaptionText); + s_htmlSysColorTable["infobackground"] = ColorUtil.FromKnownColor(KnownColor.Info); + s_htmlSysColorTable["infotext"] = ColorUtil.FromKnownColor(KnownColor.InfoText); + s_htmlSysColorTable["menu"] = ColorUtil.FromKnownColor(KnownColor.Menu); + s_htmlSysColorTable["menutext"] = ColorUtil.FromKnownColor(KnownColor.MenuText); + s_htmlSysColorTable["scrollbar"] = ColorUtil.FromKnownColor(KnownColor.ScrollBar); + s_htmlSysColorTable["threeddarkshadow"] = ColorUtil.FromKnownColor(KnownColor.ControlDarkDark); + s_htmlSysColorTable["threedface"] = ColorUtil.FromKnownColor(KnownColor.Control); + s_htmlSysColorTable["threedhighlight"] = ColorUtil.FromKnownColor(KnownColor.ControlLight); + s_htmlSysColorTable["threedlightshadow"] = ColorUtil.FromKnownColor(KnownColor.ControlLightLight); + s_htmlSysColorTable["window"] = ColorUtil.FromKnownColor(KnownColor.Window); + s_htmlSysColorTable["windowframe"] = ColorUtil.FromKnownColor(KnownColor.WindowFrame); + s_htmlSysColorTable["windowtext"] = ColorUtil.FromKnownColor(KnownColor.WindowText); } } } diff --git a/src/System.Drawing.Common/src/System/Drawing/Font.cs b/src/System.Drawing.Common/src/System/Drawing/Font.cs index bb4990911f09..763165287dee 100644 --- a/src/System.Drawing.Common/src/System/Drawing/Font.cs +++ b/src/System.Drawing.Common/src/System/Drawing/Font.cs @@ -105,7 +105,7 @@ public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, /// public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont) { - if (!float.IsFinite(emSize) || emSize <= 0) + if (float.IsNaN(emSize) || float.IsInfinity(emSize) || emSize <= 0) { throw new ArgumentException(SR.Format(SR.InvalidBoundArgument, "emSize", emSize, 0, "System.Single.MaxValue"), "emSize"); } @@ -222,7 +222,7 @@ private void Initialize(FontFamily family, float emSize, FontStyle style, Graphi throw new ArgumentNullException(nameof(family)); } - if (!float.IsFinite(emSize) || emSize <= 0) + if (float.IsNaN(emSize) || float.IsInfinity(emSize) || emSize <= 0) { throw new ArgumentException(SR.Format(SR.InvalidBoundArgument, nameof(emSize), emSize, 0, "System.Single.MaxValue"), nameof(emSize)); } diff --git a/src/System.Drawing.Common/src/System/Drawing/SystemBrushes.cs b/src/System.Drawing.Common/src/System/Drawing/SystemBrushes.cs index adef01ccc28f..c3aad7a83552 100644 --- a/src/System.Drawing.Common/src/System/Drawing/SystemBrushes.cs +++ b/src/System.Drawing.Common/src/System/Drawing/SystemBrushes.cs @@ -55,7 +55,7 @@ public static class SystemBrushes public static Brush FromSystemColor(Color c) { - if (!c.IsSystemColor) + if (!ColorUtil.IsSystemColor(c)) { throw new ArgumentException(SR.Format(SR.ColorNotSystemColor, c.ToString())); } diff --git a/src/System.Drawing.Common/src/System/Drawing/SystemColors.cs b/src/System.Drawing.Common/src/System/Drawing/SystemColors.cs index 3583e4f9408e..ca6ee2dd3791 100644 --- a/src/System.Drawing.Common/src/System/Drawing/SystemColors.cs +++ b/src/System.Drawing.Common/src/System/Drawing/SystemColors.cs @@ -6,47 +6,47 @@ namespace System.Drawing { public static class SystemColors { - public static Color ActiveBorder => Color.FromKnownColor(KnownColor.ActiveBorder); - public static Color ActiveCaption => Color.FromKnownColor(KnownColor.ActiveCaption); - public static Color ActiveCaptionText => Color.FromKnownColor(KnownColor.ActiveCaptionText); - public static Color AppWorkspace => Color.FromKnownColor(KnownColor.AppWorkspace); - - public static Color ButtonFace => Color.FromKnownColor(KnownColor.ButtonFace); - public static Color ButtonHighlight => Color.FromKnownColor(KnownColor.ButtonHighlight); - public static Color ButtonShadow => Color.FromKnownColor(KnownColor.ButtonShadow); - - public static Color Control => Color.FromKnownColor(KnownColor.Control); - public static Color ControlDark => Color.FromKnownColor(KnownColor.ControlDark); - public static Color ControlDarkDark => Color.FromKnownColor(KnownColor.ControlDarkDark); - public static Color ControlLight => Color.FromKnownColor(KnownColor.ControlLight); - public static Color ControlLightLight => Color.FromKnownColor(KnownColor.ControlLightLight); - public static Color ControlText => Color.FromKnownColor(KnownColor.ControlText); - - public static Color Desktop => Color.FromKnownColor(KnownColor.Desktop); - - public static Color GradientActiveCaption => Color.FromKnownColor(KnownColor.GradientActiveCaption); - public static Color GradientInactiveCaption => Color.FromKnownColor(KnownColor.GradientInactiveCaption); - public static Color GrayText => Color.FromKnownColor(KnownColor.GrayText); - - public static Color Highlight => Color.FromKnownColor(KnownColor.Highlight); - public static Color HighlightText => Color.FromKnownColor(KnownColor.HighlightText); - public static Color HotTrack => Color.FromKnownColor(KnownColor.HotTrack); - - public static Color InactiveBorder => Color.FromKnownColor(KnownColor.InactiveBorder); - public static Color InactiveCaption => Color.FromKnownColor(KnownColor.InactiveCaption); - public static Color InactiveCaptionText => Color.FromKnownColor(KnownColor.InactiveCaptionText); - public static Color Info => Color.FromKnownColor(KnownColor.Info); - public static Color InfoText => Color.FromKnownColor(KnownColor.InfoText); - - public static Color Menu => Color.FromKnownColor(KnownColor.Menu); - public static Color MenuBar => Color.FromKnownColor(KnownColor.MenuBar); - public static Color MenuHighlight => Color.FromKnownColor(KnownColor.MenuHighlight); - public static Color MenuText => Color.FromKnownColor(KnownColor.MenuText); - - public static Color ScrollBar => Color.FromKnownColor(KnownColor.ScrollBar); - - public static Color Window => Color.FromKnownColor(KnownColor.Window); - public static Color WindowFrame => Color.FromKnownColor(KnownColor.WindowFrame); - public static Color WindowText => Color.FromKnownColor(KnownColor.WindowText); + public static Color ActiveBorder => ColorUtil.FromKnownColor(KnownColor.ActiveBorder); + public static Color ActiveCaption => ColorUtil.FromKnownColor(KnownColor.ActiveCaption); + public static Color ActiveCaptionText => ColorUtil.FromKnownColor(KnownColor.ActiveCaptionText); + public static Color AppWorkspace => ColorUtil.FromKnownColor(KnownColor.AppWorkspace); + + public static Color ButtonFace => ColorUtil.FromKnownColor(KnownColor.ButtonFace); + public static Color ButtonHighlight => ColorUtil.FromKnownColor(KnownColor.ButtonHighlight); + public static Color ButtonShadow => ColorUtil.FromKnownColor(KnownColor.ButtonShadow); + + public static Color Control => ColorUtil.FromKnownColor(KnownColor.Control); + public static Color ControlDark => ColorUtil.FromKnownColor(KnownColor.ControlDark); + public static Color ControlDarkDark => ColorUtil.FromKnownColor(KnownColor.ControlDarkDark); + public static Color ControlLight => ColorUtil.FromKnownColor(KnownColor.ControlLight); + public static Color ControlLightLight => ColorUtil.FromKnownColor(KnownColor.ControlLightLight); + public static Color ControlText => ColorUtil.FromKnownColor(KnownColor.ControlText); + + public static Color Desktop => ColorUtil.FromKnownColor(KnownColor.Desktop); + + public static Color GradientActiveCaption => ColorUtil.FromKnownColor(KnownColor.GradientActiveCaption); + public static Color GradientInactiveCaption => ColorUtil.FromKnownColor(KnownColor.GradientInactiveCaption); + public static Color GrayText => ColorUtil.FromKnownColor(KnownColor.GrayText); + + public static Color Highlight => ColorUtil.FromKnownColor(KnownColor.Highlight); + public static Color HighlightText => ColorUtil.FromKnownColor(KnownColor.HighlightText); + public static Color HotTrack => ColorUtil.FromKnownColor(KnownColor.HotTrack); + + public static Color InactiveBorder => ColorUtil.FromKnownColor(KnownColor.InactiveBorder); + public static Color InactiveCaption => ColorUtil.FromKnownColor(KnownColor.InactiveCaption); + public static Color InactiveCaptionText => ColorUtil.FromKnownColor(KnownColor.InactiveCaptionText); + public static Color Info => ColorUtil.FromKnownColor(KnownColor.Info); + public static Color InfoText => ColorUtil.FromKnownColor(KnownColor.InfoText); + + public static Color Menu => ColorUtil.FromKnownColor(KnownColor.Menu); + public static Color MenuBar => ColorUtil.FromKnownColor(KnownColor.MenuBar); + public static Color MenuHighlight => ColorUtil.FromKnownColor(KnownColor.MenuHighlight); + public static Color MenuText => ColorUtil.FromKnownColor(KnownColor.MenuText); + + public static Color ScrollBar => ColorUtil.FromKnownColor(KnownColor.ScrollBar); + + public static Color Window => ColorUtil.FromKnownColor(KnownColor.Window); + public static Color WindowFrame => ColorUtil.FromKnownColor(KnownColor.WindowFrame); + public static Color WindowText => ColorUtil.FromKnownColor(KnownColor.WindowText); } } diff --git a/src/System.Drawing.Common/src/System/Drawing/SystemPens.cs b/src/System.Drawing.Common/src/System/Drawing/SystemPens.cs index b541492d961b..743d120ea199 100644 --- a/src/System.Drawing.Common/src/System/Drawing/SystemPens.cs +++ b/src/System.Drawing.Common/src/System/Drawing/SystemPens.cs @@ -56,7 +56,7 @@ public static class SystemPens public static Pen FromSystemColor(Color c) { - if (!c.IsSystemColor) + if (!ColorUtil.IsSystemColor(c)) { throw new ArgumentException(SR.Format(SR.ColorNotSystemColor, c.ToString())); } diff --git a/src/System.Drawing.Common/src/Unix/System.Drawing/ColorTranslator.cs b/src/System.Drawing.Common/src/Unix/System.Drawing/ColorTranslator.cs index d3f5f9e74c81..f3a184ba6378 100644 --- a/src/System.Drawing.Common/src/Unix/System.Drawing/ColorTranslator.cs +++ b/src/System.Drawing.Common/src/Unix/System.Drawing/ColorTranslator.cs @@ -113,7 +113,7 @@ public static string ToHtml(Color c) if (c.IsEmpty) return String.Empty; - if (c.IsSystemColor) + if (ColorUtil.IsSystemColor(c)) { KnownColor kc = c.ToKnownColor(); switch (kc) diff --git a/src/System.Drawing.Common/src/Unix/System.Drawing/KnownColors.cs b/src/System.Drawing.Common/src/Unix/System.Drawing/KnownColors.cs index 4313a5450775..a8bafc40fba7 100644 --- a/src/System.Drawing.Common/src/Unix/System.Drawing/KnownColors.cs +++ b/src/System.Drawing.Common/src/Unix/System.Drawing/KnownColors.cs @@ -273,7 +273,7 @@ static void RetrieveWindowsSystemColors () public static Color FromKnownColor(KnownColor kc) { - return Color.FromKnownColor(kc); + return ColorUtil.FromKnownColor(kc); } public static string GetName(short kc) diff --git a/src/System.Drawing.Common/src/Unix/System.Drawing/SystemPens.cs b/src/System.Drawing.Common/src/Unix/System.Drawing/SystemPens.cs index d997d03ed855..1d3fcf55400b 100644 --- a/src/System.Drawing.Common/src/Unix/System.Drawing/SystemPens.cs +++ b/src/System.Drawing.Common/src/Unix/System.Drawing/SystemPens.cs @@ -288,7 +288,7 @@ public static Pen WindowText public static Pen FromSystemColor(Color c) { - if (c.IsSystemColor) + if (ColorUtil.IsSystemColor(c)) { Pen newPen = new Pen(c); newPen.isModifiable = false; diff --git a/src/System.Drawing.Common/src/misc/DpiHelper.cs b/src/System.Drawing.Common/src/misc/DpiHelper.cs index a883a2e9b2a6..f9170ba22396 100644 --- a/src/System.Drawing.Common/src/misc/DpiHelper.cs +++ b/src/System.Drawing.Common/src/misc/DpiHelper.cs @@ -29,7 +29,7 @@ internal static class DpiHelper private static double s_logicalToDeviceUnitsScalingFactorX = 0.0; private static double s_logicalToDeviceUnitsScalingFactorY = 0.0; - private static bool s_enableHighDpi = false; + private static bool s_enableHighDpi = true; private static InterpolationMode s_interpolationMode = InterpolationMode.Invalid; private static void Initialize() @@ -39,17 +39,8 @@ private static void Initialize() return; } - try - { - string value = ConfigurationManager.AppSettings.Get(EnableHighDpiConfigurationValueName); - if (string.Equals(value, "true", StringComparison.InvariantCultureIgnoreCase)) - { - s_enableHighDpi = true; - } - } - catch - { - } + // NOTE: In the .NET Framework, this value can be controlled via ConfigurationManager. + // In .NET Core, the value always defaults to the value "true". if (s_enableHighDpi) { diff --git a/src/System.Drawing.Common/src/misc/InvalidEnumArgumentException.cs b/src/System.Drawing.Common/src/misc/InvalidEnumArgumentException.cs new file mode 100644 index 000000000000..62de17473096 --- /dev/null +++ b/src/System.Drawing.Common/src/misc/InvalidEnumArgumentException.cs @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Globalization; +using System.Runtime.Serialization; + +namespace System.ComponentModel +{ + /// + /// The exception that is thrown when using invalid arguments that are enumerators. + /// + internal class InvalidEnumArgumentException : ArgumentException + { + /// + /// Initializes a new instance of the class without a message. + /// + public InvalidEnumArgumentException() : this(null) + { + } + + /// + /// Initializes a new instance of the class with + /// the specified message. + /// + public InvalidEnumArgumentException(string message) + : base(message) + { + } + + /// + /// Initializes a new instance of the Exception class with a specified error message and a + /// reference to the inner exception that is the cause of this exception. + /// FxCop CA1032: Multiple constructors are required to correctly implement a custom exception. + /// + public InvalidEnumArgumentException(string message, Exception innerException) + : base(message, innerException) + { + } + + /// + /// Initializes a new instance of the class with a + /// message generated from the argument, invalid value, and enumeration + /// class. + /// + public InvalidEnumArgumentException(string argumentName, int invalidValue, Type enumClass) + : base(SR.Format(SR.InvalidEnumArgument, + argumentName, + invalidValue.ToString(CultureInfo.CurrentCulture), + enumClass.Name), argumentName) + { + } + + /// + /// Need this constructor since Exception implements ISerializable. We don't have any fields, + /// so just forward this to base. + /// + protected InvalidEnumArgumentException(SerializationInfo info, StreamingContext context) : base(info, context) + { + throw new PlatformNotSupportedException(); + } + } +} \ No newline at end of file diff --git a/src/System.Drawing.Common/tests/Drawing2D/GraphicsPathTests.cs b/src/System.Drawing.Common/tests/Drawing2D/GraphicsPathTests.cs index f60e144f5ace..98dd7c2485fc 100644 --- a/src/System.Drawing.Common/tests/Drawing2D/GraphicsPathTests.cs +++ b/src/System.Drawing.Common/tests/Drawing2D/GraphicsPathTests.cs @@ -149,7 +149,7 @@ public void GraphicsPath_InvalidFillMode_ThrowsInvalidEnumArgumentException(Fill { using (GraphicsPath gp = new GraphicsPath()) { - AssertExtensions.Throws("value", () => gp.FillMode = fillMode); + Assert.ThrowsAny(() => gp.FillMode = fillMode); } } diff --git a/src/System.Drawing.Common/tests/Drawing2D/LinearGradientBrushTests.cs b/src/System.Drawing.Common/tests/Drawing2D/LinearGradientBrushTests.cs index bce9dce6cd0d..5704a8062338 100644 --- a/src/System.Drawing.Common/tests/Drawing2D/LinearGradientBrushTests.cs +++ b/src/System.Drawing.Common/tests/Drawing2D/LinearGradientBrushTests.cs @@ -242,8 +242,8 @@ public void Ctor_ZeroHeight_ThrowsArgumentException() [InlineData(LinearGradientMode.BackwardDiagonal + 1)] public void Ctor_InvalidLinearGradientMode_ThrowsEnumArgumentException(LinearGradientMode linearGradientMode) { - AssertExtensions.Throws("linearGradientMode", () => new LinearGradientBrush(new Rectangle(1, 2, 3, 4), Color.Empty, Color.Empty, linearGradientMode)); - AssertExtensions.Throws("linearGradientMode", () => new LinearGradientBrush(new RectangleF(1, 2, 3, 4), Color.Empty, Color.Empty, linearGradientMode)); + Assert.ThrowsAny(() => new LinearGradientBrush(new Rectangle(1, 2, 3, 4), Color.Empty, Color.Empty, linearGradientMode)); + Assert.ThrowsAny(() => new LinearGradientBrush(new RectangleF(1, 2, 3, 4), Color.Empty, Color.Empty, linearGradientMode)); } public static IEnumerable Ctor_HatchStyle_ForeColor_BackColor_TestData() @@ -456,7 +456,7 @@ public void InterpolationColors_SetWithExistingInterpolationColors_OverwritesInt var blend = new ColorBlend { Colors = new Color[] { Color.Red, Color.PeachPuff, Color.PowderBlue }, - Positions = new float[] { 0, 0.5f, 1f } + Positions = new float[] { 0, 0.5f, 1f } }; brush.InterpolationColors = blend; Assert.Equal(blend.Colors.Select(c => Color.FromArgb(c.ToArgb())), brush.InterpolationColors.Colors); @@ -668,7 +668,7 @@ public void WrapMode_SetValid_GetReturnsExpected(WrapMode wrapMode) public void WrapMode_SetInvalid_ThrowsInvalidEnumArgumentException(WrapMode wrapMode) { var brush = new LinearGradientBrush(new Rectangle(1, 2, 3, 4), Color.Plum, Color.Red, 45, true); - AssertExtensions.Throws("value", () => brush.WrapMode = wrapMode); + Assert.ThrowsAny(() => brush.WrapMode = wrapMode); } [ConditionalFact(Helpers.GdiplusIsAvailable)] diff --git a/src/System.Drawing.Common/tests/Drawing2D/PathGradientBrushTests.cs b/src/System.Drawing.Common/tests/Drawing2D/PathGradientBrushTests.cs index d936bc9f4502..7edf6ea8dd7f 100644 --- a/src/System.Drawing.Common/tests/Drawing2D/PathGradientBrushTests.cs +++ b/src/System.Drawing.Common/tests/Drawing2D/PathGradientBrushTests.cs @@ -96,10 +96,10 @@ public void Ctor_PointsLengthLessThenTwo_ThrowsOutOfMemoryException(int pointsLe [ConditionalFact(Helpers.GdiplusIsAvailable)] public void Ctor_InvalidWrapMode_ThrowsInvalidEnumArgumentException() { - AssertExtensions.Throws("wrapMode", () => + Assert.ThrowsAny(() => new PathGradientBrush(_defaultIntPoints, (WrapMode)int.MaxValue)); - AssertExtensions.Throws("wrapMode", () => + Assert.ThrowsAny(() => new PathGradientBrush(_defaultFloatPoints, (WrapMode)int.MaxValue)); } @@ -1065,7 +1065,7 @@ public void WrapMode_Invalid_InvalidEnumArgumentException() { using (PathGradientBrush brush = new PathGradientBrush(_defaultFloatPoints)) { - AssertExtensions.Throws("value", () => brush.WrapMode = (WrapMode)int.MinValue); + Assert.ThrowsAny(() => brush.WrapMode = (WrapMode)int.MinValue); } } diff --git a/src/System.Drawing.Common/tests/GraphicsTests.cs b/src/System.Drawing.Common/tests/GraphicsTests.cs index ea071cf8e631..0e24024ca339 100644 --- a/src/System.Drawing.Common/tests/GraphicsTests.cs +++ b/src/System.Drawing.Common/tests/GraphicsTests.cs @@ -405,7 +405,7 @@ public void CompositingMode_SetInvalid_ThrowsInvalidEnumArgumentException(Compos using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { - AssertExtensions.Throws("value", () => graphics.CompositingMode = compositingMode); + Assert.ThrowsAny(() => graphics.CompositingMode = compositingMode); } } @@ -500,7 +500,7 @@ public void CompositingQuality_SetInvalid_ThrowsInvalidEnumArgumentException(Com using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { - AssertExtensions.Throws("value", () => graphics.CompositingQuality = compositingQuality); + Assert.ThrowsAny(() => graphics.CompositingQuality = compositingQuality); } } @@ -713,7 +713,7 @@ public void InterpolationMode_SetInvalid_ThrowsInvalidEnumArgumentException(Inte using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { - AssertExtensions.Throws("value", () => graphics.InterpolationMode = interpolationMode); + Assert.ThrowsAny(() => graphics.InterpolationMode = interpolationMode); } } @@ -850,7 +850,7 @@ public void PageUnit_SetInvalid_ThrowsInvalidEnumArgumentException(GraphicsUnit using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { - AssertExtensions.Throws("value", () => graphics.PageUnit = pageUnit); + Assert.ThrowsAny(() => graphics.PageUnit = pageUnit); } } @@ -923,7 +923,7 @@ public void PixelOffsetMode_SetInvalid_ThrowsInvalidEnumArgumentException(PixelO using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { - AssertExtensions.Throws("value", () => graphics.PixelOffsetMode = pixelOffsetMode); + Assert.ThrowsAny(() => graphics.PixelOffsetMode = pixelOffsetMode); } } @@ -1087,7 +1087,7 @@ public void SmoothingMode_SetInvalid_ThrowsInvalidEnumArgumentException(Smoothin using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { - AssertExtensions.Throws("value", () => graphics.SmoothingMode = smoothingMode); + Assert.ThrowsAny(() => graphics.SmoothingMode = smoothingMode); } } @@ -1220,7 +1220,7 @@ public void TextRenderingHint_SetInvalid_ThrowsInvalidEnumArgumentException(Text using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { - AssertExtensions.Throws("value", () => graphics.TextRenderingHint = textRenderingHint); + Assert.ThrowsAny(() => graphics.TextRenderingHint = textRenderingHint); } } @@ -1932,7 +1932,7 @@ public void CopyFromScreen_InvalidCopyPixelOperation_ThrowsInvalidEnumArgumentEx using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { - AssertExtensions.Throws("copyPixelOperation", "value", () => graphics.CopyFromScreen(1, 2, 3, 4, Size.Empty, copyPixelOperation)); + Assert.ThrowsAny(() => graphics.CopyFromScreen(1, 2, 3, 4, Size.Empty, copyPixelOperation)); } } diff --git a/src/System.Drawing.Common/tests/Imaging/BitmapDataTests.cs b/src/System.Drawing.Common/tests/Imaging/BitmapDataTests.cs index 74fe69d123ab..8ac78e44eaa4 100644 --- a/src/System.Drawing.Common/tests/Imaging/BitmapDataTests.cs +++ b/src/System.Drawing.Common/tests/Imaging/BitmapDataTests.cs @@ -111,7 +111,7 @@ public void PixelFormat_SetValid_ReturnsExpected(PixelFormat pixelFormat) public void PixelFormat_SetInvalid_ThrowsInvalidEnumException() { BitmapData bd = new BitmapData(); - Assert.Throws(() => bd.PixelFormat = (PixelFormat)(-1)); + Assert.ThrowsAny(() => bd.PixelFormat = (PixelFormat)(-1)); } } } diff --git a/src/System.Drawing.Common/tests/PenTests.cs b/src/System.Drawing.Common/tests/PenTests.cs index 207d8f2c8034..3670462c7c10 100644 --- a/src/System.Drawing.Common/tests/PenTests.cs +++ b/src/System.Drawing.Common/tests/PenTests.cs @@ -153,7 +153,7 @@ public void Alignment_SetInvalid_ThrowsInvalidEnumArgumentException(PenAlignment using (var brush = new SolidBrush(Color.Red)) using (var pen = new Pen(brush)) { - AssertExtensions.Throws("value", () => pen.Alignment = aligment); + Assert.ThrowsAny(() => pen.Alignment = aligment); } } @@ -576,7 +576,7 @@ public void DashCap_SetInvalid_ThrowsInvalidEnumArgumentException(DashCap dashCa using (var brush = new SolidBrush(Color.Red)) using (var pen = new Pen(brush)) { - AssertExtensions.Throws("value", () => pen.DashCap = dashCap); + Assert.ThrowsAny(() => pen.DashCap = dashCap); } } @@ -741,7 +741,7 @@ public void DashStyle_SetInvalid_ThrowsInvalidEnumArgumentException(DashStyle da using (var brush = new SolidBrush(Color.Red)) using (var pen = new Pen(brush)) { - AssertExtensions.Throws("value", () => pen.DashStyle = dashStyle); + Assert.ThrowsAny(() => pen.DashStyle = dashStyle); } } @@ -802,7 +802,7 @@ public void EndCap_SetInvalid_ThrowsInvalidEnumArgumentException(LineCap lineCap using (var brush = new SolidBrush(Color.Red)) using (var pen = new Pen(brush)) { - AssertExtensions.Throws("value", () => pen.EndCap = lineCap); + Assert.ThrowsAny(() => pen.EndCap = lineCap); } } @@ -843,7 +843,7 @@ public void LineJoin_SetInvalid_ThrowsInvalidEnumArgumentException(LineJoin line using (var brush = new SolidBrush(Color.Red)) using (var pen = new Pen(brush)) { - AssertExtensions.Throws("value", () => pen.LineJoin = lineJoin); + Assert.ThrowsAny(() => pen.LineJoin = lineJoin); } } @@ -1224,7 +1224,7 @@ public void StartCap_SetInvalid_ThrowsInvalidEnumArgumentException(LineCap lineC using (var brush = new SolidBrush(Color.Red)) using (var pen = new Pen(brush)) { - AssertExtensions.Throws("value", () => pen.StartCap = lineCap); + Assert.ThrowsAny(() => pen.StartCap = lineCap); } } diff --git a/src/System.Drawing.Common/tests/Printing/PrinterResolutionTests.cs b/src/System.Drawing.Common/tests/Printing/PrinterResolutionTests.cs index 91e30e390ccc..9f6f1d00a852 100644 --- a/src/System.Drawing.Common/tests/Printing/PrinterResolutionTests.cs +++ b/src/System.Drawing.Common/tests/Printing/PrinterResolutionTests.cs @@ -64,7 +64,7 @@ public void Kind_ReturnsExpected(PrinterResolutionKind kind) public void Kind_InvalidEnum_ThrowsInvalidEnumArgumentException(PrinterResolutionKind overflowKind) { PrinterResolution pr = new PrinterResolution(); - Assert.Throws(() => pr.Kind = overflowKind); + Assert.ThrowsAny(() => pr.Kind = overflowKind); } } } diff --git a/src/System.Drawing.Common/tests/StringFormatTests.cs b/src/System.Drawing.Common/tests/StringFormatTests.cs index 3de73eb48ce4..146e77bbf686 100644 --- a/src/System.Drawing.Common/tests/StringFormatTests.cs +++ b/src/System.Drawing.Common/tests/StringFormatTests.cs @@ -287,7 +287,7 @@ public void Alignment_SetInvalid_ThrowsInvalidEnumArgumentException(StringAlignm { using (var format = new StringFormat()) { - AssertExtensions.Throws("value", () => format.Alignment = alignment); + Assert.ThrowsAny(() => format.Alignment = alignment); } } @@ -363,7 +363,7 @@ public void LineAlignment_SetInvalid_ThrowsInvalidEnumArgumentException(StringAl { using (var format = new StringFormat()) { - AssertExtensions.Throws("value", () => format.LineAlignment = alignment); + Assert.ThrowsAny(() => format.LineAlignment = alignment); } } @@ -397,7 +397,7 @@ public void HotKeyPrefix_SetInvalid_ThrowsInvalidEnumArgumentException(HotkeyPre { using (var format = new StringFormat()) { - AssertExtensions.Throws("value", () => format.HotkeyPrefix = prefix); + Assert.ThrowsAny(() => format.HotkeyPrefix = prefix); } } @@ -429,7 +429,7 @@ public void Trimming_SetInvalid_ThrowsInvalidEnumArgumentException(StringTrimmin { using (var format = new StringFormat()) { - AssertExtensions.Throws("value", () => format.Trimming = trimming); + Assert.ThrowsAny(() => format.Trimming = trimming); } } diff --git a/src/System.Drawing.Common/tests/TextureBrushTests.cs b/src/System.Drawing.Common/tests/TextureBrushTests.cs index 0fdb6dc06ed9..bb93324f0d0a 100644 --- a/src/System.Drawing.Common/tests/TextureBrushTests.cs +++ b/src/System.Drawing.Common/tests/TextureBrushTests.cs @@ -302,9 +302,9 @@ public void Ctor_InvalidWrapMode_ThrowsInvalidEnumArgumentException(WrapMode wra { using (var image = new Bitmap(10, 10)) { - AssertExtensions.Throws("wrapMode", () => new TextureBrush(image, wrapMode)); - AssertExtensions.Throws("wrapMode", () => new TextureBrush(image, wrapMode, RectangleF.Empty)); - AssertExtensions.Throws("wrapMode", () => new TextureBrush(image, wrapMode, Rectangle.Empty)); + Assert.ThrowsAny(() => new TextureBrush(image, wrapMode)); + Assert.ThrowsAny(() => new TextureBrush(image, wrapMode, RectangleF.Empty)); + Assert.ThrowsAny(() => new TextureBrush(image, wrapMode, Rectangle.Empty)); } } @@ -795,7 +795,7 @@ public void WrapMode_SetInvalid_ThrowsInvalidEnumArgumentException(WrapMode wrap using (var image = new Bitmap(10, 10)) using (var brush = new TextureBrush(image)) { - AssertExtensions.Throws("value", () => brush.WrapMode = wrapMode); + Assert.ThrowsAny(() => brush.WrapMode = wrapMode); } } diff --git a/src/System.Drawing.Primitives/src/System.Drawing.Primitives.csproj b/src/System.Drawing.Primitives/src/System.Drawing.Primitives.csproj index 2b49c5a61a7c..75f440ee09c5 100644 --- a/src/System.Drawing.Primitives/src/System.Drawing.Primitives.csproj +++ b/src/System.Drawing.Primitives/src/System.Drawing.Primitives.csproj @@ -38,13 +38,18 @@ System\Drawing\ColorTable.cs + + System\Drawing\ColorUtil.netcoreapp21.cs + + + System\Drawing\KnownColor.cs + System\Drawing\KnownColorTable.cs Common\System\Numerics\Hashing\HashHelpers.cs - From 17130d8d5f036ba3a77e7addcb786704d8344c56 Mon Sep 17 00:00:00 2001 From: Eric Mellino Date: Tue, 1 Aug 2017 15:45:40 -0700 Subject: [PATCH 2/2] Respond to PR feedback. --- external/netcoreapp/netcoreapp.depproj | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/external/netcoreapp/netcoreapp.depproj b/external/netcoreapp/netcoreapp.depproj index c52459d9fe0b..d4dcfcfa703f 100644 --- a/external/netcoreapp/netcoreapp.depproj +++ b/external/netcoreapp/netcoreapp.depproj @@ -1,10 +1,12 @@  + true Reference - 2.0.0-preview2-25407-01 + 2.0.0 netcoreapp2.0 @@ -19,10 +21,6 @@ $(RefPath) - - - $(TestHostRootPath) -