-
Notifications
You must be signed in to change notification settings - Fork 325
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 some polyfill to simplify code across compilations #3974
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace System; | ||
/// <summary> | ||
/// A polyfill helper for Guid. | ||
/// </summary> | ||
internal static class GuidPolyfill | ||
{ | ||
public static Guid Parse(string s, IFormatProvider? provider) | ||
=> Guid.Parse(s | ||
#if NET7_0_OR_GREATER | ||
, System.Globalization.CultureInfo.InvariantCulture | ||
#endif | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace System.Text; | ||
internal static class StringBuilderPolyfill | ||
{ | ||
#if !NET7_0_OR_GREATER | ||
[Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Added to match new API.")] | ||
public static StringBuilder Append(this StringBuilder builder, IFormatProvider? provider, string? value) | ||
=> builder.Append(value); | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,7 @@ | |
|
||
using System; | ||
using System.Collections.Generic; | ||
#if NET7_0_OR_GREATER | ||
using System.Globalization; | ||
#endif | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
|
@@ -270,11 +268,7 @@ protected override void ProtectedSetPropertyValue(TestProperty property, object? | |
} | ||
else if (value is string guidString) | ||
{ | ||
#if NET7_0_OR_GREATER | ||
Id = Guid.Parse(guidString, CultureInfo.InvariantCulture); | ||
#else | ||
Id = Guid.Parse(guidString); | ||
#endif | ||
Id = GuidPolyfill.Parse(guidString, CultureInfo.InvariantCulture); | ||
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. should the used signature be the "older" one, I mean from user perspective looks like the culture is important...but it's important only for one version...so I wonder if we should have the one without culture and setup the correct default for the newer one. 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. That's a good suggestion. I don't see us using anything else than Maybe I will keep it as-is. |
||
} | ||
else | ||
{ | ||
|
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.
@MarcoRossignoli Was suggesting to have only one class called
Polyfill
that would host all polyfills as sub-classes (e.g.Polyfill.Guid.Parse
. It looks like a good idea but doesn't allow for extension methods (need to be defined at top class-level).We can:
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 see theoretical way around it but it requires three classes and instances. Seems like PolyfillGuid or GuidPolyfill in separate class is much easier way to go.
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.
it's ok as-is to me.