-
Notifications
You must be signed in to change notification settings - Fork 5.3k
add OSPlatform.macOS, make OSPlatform.Equal use OrdinalIgnoreCaseComparison #39064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
5909ffe
d586408
76783a6
2d2ed3e
f388f03
7a8f548
8a3277e
d3e751d
8ae72cf
f3c439a
84d959a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,8 @@ | ||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||
|
|
||||||
| using System.ComponentModel; | ||||||
|
|
||||||
| namespace System.Runtime.InteropServices | ||||||
| { | ||||||
| public readonly struct OSPlatform : IEquatable<OSPlatform> | ||||||
|
|
@@ -15,7 +17,10 @@ namespace System.Runtime.InteropServices | |||||
|
|
||||||
| public static OSPlatform Linux { get; } = new OSPlatform("LINUX"); | ||||||
|
|
||||||
| public static OSPlatform OSX { get; } = new OSPlatform("OSX"); | ||||||
| public static OSPlatform macOS { get; } = new OSPlatform("MACOS"); | ||||||
|
|
||||||
| [EditorBrowsable(EditorBrowsableState.Never)] // https://github.com/dotnet/runtime/issues/33331#issuecomment-650326500 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this link really useful for context? It points to several screens of API review notes, and it does not say much useful about the OSX. Should this rather say "// superseded by macOS" ? |
||||||
| public static OSPlatform OSX { get; } = macOS; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a breaking change.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, then we should add the macOS/OSX magic to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think we should be changing the string identifier for OSX/macOS. It should stay as OSX. OSX is hardcoded in many places that are hard/impossible to fix, like NuGet RIDs. We are not gaining much by changing it ad-hoc in subset of places. If we want to change it, it should be done everywhere and it should be a feature on its own.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We discussed this during the Design Review meeting today and got a direction on how to address this breaking change risk while still handling equivalence. The comments are posted on #33331, but at a high-level,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| public static OSPlatform iOS { get; } = new OSPlatform("IOS"); | ||||||
|
|
||||||
|
|
@@ -30,7 +35,7 @@ private OSPlatform(string osPlatform) | |||||
| if (osPlatform == null) throw new ArgumentNullException(nameof(osPlatform)); | ||||||
| if (osPlatform.Length == 0) throw new ArgumentException(SR.Argument_EmptyValue, nameof(osPlatform)); | ||||||
|
|
||||||
| _osPlatform = osPlatform; | ||||||
| _osPlatform = osPlatform.Equals("OSX", StringComparison.OrdinalIgnoreCase) ? "MACOS" : osPlatform; | ||||||
| } | ||||||
|
|
||||||
| public static OSPlatform Create(string osPlatform) | ||||||
|
|
@@ -40,17 +45,12 @@ public static OSPlatform Create(string osPlatform) | |||||
|
|
||||||
| public bool Equals(OSPlatform other) | ||||||
| { | ||||||
| return Equals(other._osPlatform); | ||||||
| } | ||||||
|
|
||||||
| internal bool Equals(string? other) | ||||||
| { | ||||||
| return string.Equals(_osPlatform, other, StringComparison.Ordinal); | ||||||
| return string.Equals(_osPlatform, other._osPlatform, StringComparison.OrdinalIgnoreCase); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is motivating this change? This will make this API quite a bit more expensive. |
||||||
| } | ||||||
|
|
||||||
| public override bool Equals(object? obj) | ||||||
| { | ||||||
| return obj is OSPlatform && Equals((OSPlatform)obj); | ||||||
| return obj is OSPlatform osPlatform && Equals(osPlatform); | ||||||
adamsitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } | ||||||
|
|
||||||
| public override int GetHashCode() | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.