From e07da04eda4dc509523026168b97a7ccb7d90184 Mon Sep 17 00:00:00 2001 From: Clinton Ingram Date: Fri, 24 Aug 2018 09:50:24 -0700 Subject: [PATCH] Remove redundant code (dotnet/corefx#31923) Commit migrated from https://github.com/dotnet/corefx/commit/ea6b4926edebbaaaafe8f968a696697cc735e058 --- .../Common/src/System/Drawing/ColorTable.cs | 33 ++++++---------------- .../src/System/Drawing/Color.cs | 8 +++--- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/libraries/Common/src/System/Drawing/ColorTable.cs b/src/libraries/Common/src/System/Drawing/ColorTable.cs index 69e9b8d..8d39964 100644 --- a/src/libraries/Common/src/System/Drawing/ColorTable.cs +++ b/src/libraries/Common/src/System/Drawing/ColorTable.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; -using System.Diagnostics; using System.Reflection; namespace System.Drawing @@ -14,34 +13,20 @@ namespace System.Drawing private static Dictionary GetColors() { - var dict = new Dictionary(StringComparer.OrdinalIgnoreCase); - FillConstants(dict, typeof(Color)); - return dict; - } - - internal static Dictionary Colors => s_colorConstants.Value; - - private static void FillConstants(Dictionary colors, Type enumType) - { - const MethodAttributes attrs = MethodAttributes.Public | MethodAttributes.Static; - foreach (PropertyInfo prop in enumType.GetProperties()) + var colors = new Dictionary(StringComparer.OrdinalIgnoreCase); + foreach (PropertyInfo prop in typeof(Color).GetProperties(BindingFlags.Public | BindingFlags.Static)) { if (prop.PropertyType == typeof(Color)) - { - Debug.Assert(prop.GetGetMethod() != null); - Debug.Assert((prop.GetGetMethod().Attributes & attrs) == attrs); colors[prop.Name] = (Color)prop.GetValue(null, null); - } } + + return colors; } - internal static bool TryGetNamedColor(string name, out Color result) => - Colors.TryGetValue(name, out result); + internal static Dictionary Colors => s_colorConstants.Value; - internal static bool IsKnownNamedColor(string name) - { - Color result; - return Colors.TryGetValue(name, out result); - } + internal static bool TryGetNamedColor(string name, out Color result) => Colors.TryGetValue(name, out result); + + internal static bool IsKnownNamedColor(string name) => Colors.TryGetValue(name, out _); } -} \ No newline at end of file +} diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs index 9c2360b..2b0554b 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs @@ -360,13 +360,13 @@ namespace System.Drawing this.knownColor = unchecked((short)knownColor); } - public byte R => (byte)(((uint)Value & ARGBRedMask) >> ARGBRedShift); + public byte R => unchecked((byte)(Value >> ARGBRedShift)); - public byte G => (byte)(((uint)Value & ARGBGreenMask) >> ARGBGreenShift); + public byte G => unchecked((byte)(Value >> ARGBGreenShift)); - public byte B => (byte)(((uint)Value & ARGBBlueMask) >> ARGBBlueShift); + public byte B => unchecked((byte)(Value >> ARGBBlueShift)); - public byte A => (byte)(((uint)Value & ARGBAlphaMask) >> ARGBAlphaShift); + public byte A => unchecked((byte)(Value >> ARGBAlphaShift)); public bool IsKnownColor => (state & StateKnownColorValid) != 0; -- 2.7.4