-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
add OSPlatform.macOS, make OSPlatform.Equal use OrdinalIgnoreCaseComparison #39064
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
hey @adamsitnik I just merged my PR #36704 which also implemented most of these new additions, so please rebase this one :) |
@akoeplinger thanks for letting me know! |
I think there was a spoken comment during the review that we could have macOS return “OSX”. If we did that, would it fee more or less hacky to you, @adamsitnik? |
...vices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs
Outdated
Show resolved
Hide resolved
...vices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs
Outdated
Show resolved
Hide resolved
...vices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs
Outdated
Show resolved
Hide resolved
it would make the following lines work: Assert.Equal(OSPlatform.OSX, OSPlatform.macOS); but not: Assert.Equal(OSPlatform.macOS, OSPlatform.Create("macOS"));
Assert.Equal(OSPlatform.OSX, OSPlatform.Create("macOS")); I like @akoeplinger idea and I am going to apply it |
@akoeplinger @jeffhandley thanks for great suggestions, the code looks much better now! |
...vices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs
Show resolved
Hide resolved
...vices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs
Show resolved
Hide resolved
public static OSPlatform macOS { get; } = new OSPlatform("MACOS"); | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] // https://github.com/dotnet/runtime/issues/33331#issuecomment-650326500 | ||
public static OSPlatform OSX { get; } = macOS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example
void Foo (OSPlatform osp)
{
if (osp.ToString() == "OSX")
return;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, then we should add the macOS/OSX magic to ToString()
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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, OSPlatform
should not try to handle equivalence between platforms itself; instead, the RuntimeInformation.IsOSPlatform
should handle it.
I've been trying to wrap my head around the Based on https://en.wikipedia.org/w/index.php?title=Macintosh_operating_systems§ion=4#Releases_2
The value returned by
But .NET 5 officially supports only Moreover it's not just about the naming, so: Assert.NotEqual(OSPlatform.OSX, OSPlatform.macOS); But for the sake of backward compatibility and usability: RuntimeInformation.IsOSPlatform(OSPlatform.OSX) // should return true for every mac OS and .NET And for .NET 5: RuntimeInformation.IsOSPlatform(OSPlatform.macOS) // should return true only on .NET 5 on macOS 10.13+ Any comments on that before I apply the changes? |
@adamsitnik the OSX -> macOS change was purely a marketing/branding change so it'd be very weird if |
public static System.Runtime.InteropServices.OSPlatform Linux { get { throw null; } } | ||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] // https://github.com/dotnet/runtime/issues/33331#issuecomment-650326500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref files should not use comments like this. They will disappear next time the file is reformatted using auto-generator.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 override bool Equals(object? obj) | ||
{ | ||
return obj is OSPlatform && Equals((OSPlatform)obj); | ||
Debug.Fail("The non generic method should not be used by BCL"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want the debug libraries to be fully usable. This should be removed.
If you would like to check that this method is not called by the BCL, it is a job for the analyzer.
internal bool Equals(string? other) | ||
{ | ||
return string.Equals(_osPlatform, other, StringComparison.Ordinal); | ||
return string.Equals(_osPlatform, other._osPlatform, StringComparison.OrdinalIgnoreCase); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 static OSPlatform macOS { get; } = new OSPlatform("MACOS"); | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] // https://github.com/dotnet/runtime/issues/33331#issuecomment-650326500 | ||
public static OSPlatform OSX { get; } = macOS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static OSPlatform OSX { get; } = macOS; | |
public static OSPlatform OSX => macOS; |
I've sent a new PR: #39209 |
Contributes to #33331
/cc @jeffhandley