This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22833 from mellinoe/system.drawing.netcoreapp20
Change System.Drawing.Common's target to netcoreapp2.0
- Loading branch information
Showing
33 changed files
with
404 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<BuildConfigurations> | ||
netcoreapp2.0 | ||
</BuildConfigurations> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> | ||
<!-- This project restores and publishes the targeting pack for specific versions of .NET Core. | ||
With this, we are able to compile assemblies against shipped, stable versions of .NET Core. --> | ||
<PropertyGroup> | ||
<BinPlaceRef>true</BinPlaceRef> | ||
<NuGetDeploySourceItem>Reference</NuGetDeploySourceItem> | ||
<NETCoreAppPackageVersion>2.0.0</NETCoreAppPackageVersion> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NETCore.App"> | ||
<Version>$(NETCoreAppPackageVersion)</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- for all configurations this project provides refs for that configuration --> | ||
<BinPlaceConfiguration Include="$(Configuration)"> | ||
<RefPath>$(RefPath)</RefPath> | ||
</BinPlaceConfiguration> | ||
</ItemGroup> | ||
|
||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.