Skip to content

Commit

Permalink
Updated subproject and polyfills
Browse files Browse the repository at this point in the history
Refactored and consolidated common polyfill definitions for better maintenance. Enabled type forwarding for `IsExternalInit` to align with .NET 5 constraints and utilized file-based inclusions instead of conditions within target files. Updated the attribute aliases for the string syntax in DateOnly and TimeOnly parse methods to comply with the consolidated definitions and avoid potential aliasing conflicts.

Resolves issues with framework compatibility and standardizes attribute usage across the codebase.
  • Loading branch information
dgmjr committed Feb 21, 2024
1 parent b2040d5 commit 5e49aa5
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Extensions
7 changes: 7 additions & 0 deletions System.Polyfills/System.Polyfills.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<ItemGroup>
<Using Include="System.Runtime.CompilerServices" />
<Using Include="System.Diagnostics.CodeAnalysis.StringSyntaxAttribute" Alias="StringSyntax" />
<Using Include="System.Diagnostics.CodeAnalysis.StringSyntaxAttribute" Alias="StringSyntaxAttribute" />
</ItemGroup>
</Project>
4 changes: 0 additions & 4 deletions System.Polyfills/System.Polyfills.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<DefineConstants Condition="'$(TargetFramework)' == 'netstandard2.0'">$(DefineConstants);NOTNETSTANDARD21ORGREATER</DefineConstants>
<DefineConstants Condition="$(TargetFramework.StartsWith('netstandard1')) OR $(TargetFramework.StartsWith('netcore'))">$(DefineConstants);NOTNETSTANDARD20ORGREATER</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(MSBuildProjectName)' != 'System.Private.CoreLib.Polyfills'">
<Using Include="System.Runtime.CompilerServices" />
<Using Include="System.Diagnostics.CodeAnalysis.StringSyntaxAttribute" Alias="StringSyntax" Condition="$(DefineConstants.Contains('NOTNET70ORGREATER'))" />
</ItemGroup>

<!-- <UsingTask TaskName="CheckForDuplicateItems" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" /> -->

Expand Down
31 changes: 20 additions & 11 deletions System.Polyfills/System.Runtime.CompilerServices/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
#if !NET6_0_OR_GREATER
#if NET5_0_OR_GREATER

[assembly: System.Runtime.CompilerServices.TypeForwardedTo(
typeof(System.Runtime.CompilerServices.IsExternalInit)
)]

#else

// 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.CompilerServices
{
/// <summary>
/// Reserved to be used by the compiler for tracking metadata. This class
/// should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class IsExternalInit { }
}
namespace System.Runtime.CompilerServices;

// https://github.com/dotnet/runtime/blob/v8.0.0/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/IsExternalInit.cs

/// <summary>
/// Reserved to be used by the compiler for tracking metadata.
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public // polyfill!
static class IsExternalInit { }

#endif
52 changes: 26 additions & 26 deletions System.Polyfills/System/DateOnly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public static DateOnly Parse(
/// <exception cref="FormatException"><paramref name="s"/> does not contain a valid string representation of a date.</exception>
public static DateOnly ParseExact(
ReadOnlySpan<char> s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] ReadOnlySpan<char> format,
[@StringSyntax(StringSyntax.DateOnlyFormat)] ReadOnlySpan<char> format,
IFormatProvider? provider = default,
DateTimeStyles style = DateTimeStyles.None
)
Expand All @@ -419,7 +419,7 @@ public static DateOnly ParseExact(
/// <exception cref="FormatException"><paramref name="s"/> does not contain a valid string representation of a date.</exception>
public static DateOnly ParseExact(
ReadOnlySpan<char> s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string[] formats
[@StringSyntax(StringSyntax.DateOnlyFormat)] string[] formats
) => ParseExact(s, formats, null, DateTimeStyles.None);

/// <summary>
Expand All @@ -436,7 +436,7 @@ public static DateOnly ParseExact(
/// <exception cref="FormatException"><paramref name="s"/> does not contain a valid string representation of a date.</exception>
public static DateOnly ParseExact(
ReadOnlySpan<char> s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string[] formats,
[@StringSyntax(StringSyntax.DateOnlyFormat)] string[] formats,
IFormatProvider? provider,
DateTimeStyles style = DateTimeStyles.None
)
Expand Down Expand Up @@ -479,7 +479,7 @@ public static DateOnly Parse(
/// <exception cref="FormatException"><paramref name="s"/> does not contain a valid string representation of a date.</exception>
public static DateOnly ParseExact(
ReadOnlySpan<char> s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] ReadOnlySpan<char> format,
[@StringSyntax(StringSyntax.DateOnlyFormat)] ReadOnlySpan<char> format,
IFormatProvider? provider = default,
DateTimeStyles style = DateTimeStyles.None
)
Expand All @@ -500,7 +500,7 @@ public static DateOnly ParseExact(
/// <exception cref="FormatException"><paramref name="s"/> does not contain a valid string representation of a date.</exception>
public static DateOnly ParseExact(
ReadOnlySpan<char> s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string[] formats
[@StringSyntax(StringSyntax.DateOnlyFormat)] string[] formats
) => ParseExact(s, formats, null, DateTimeStyles.None);

/// <summary>
Expand All @@ -517,7 +517,7 @@ public static DateOnly ParseExact(
/// <exception cref="FormatException"><paramref name="s"/> does not contain a valid string representation of a date.</exception>
public static DateOnly ParseExact(
ReadOnlySpan<char> s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string[] formats,
[@StringSyntax(StringSyntax.DateOnlyFormat)] string[] formats,
IFormatProvider? provider,
DateTimeStyles style = DateTimeStyles.None
)
Expand Down Expand Up @@ -565,7 +565,7 @@ public static DateOnly Parse(
/// <exception cref="FormatException"><paramref name="s"/> does not contain a valid string representation of a date.</exception>
public static DateOnly ParseExact(
string s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string format
[@StringSyntax(StringSyntax.DateOnlyFormat)] string format
) => ParseExact(s, format, null, DateTimeStyles.None);

/// <summary>
Expand All @@ -582,7 +582,7 @@ public static DateOnly ParseExact(
/// <exception cref="FormatException"><paramref name="s"/> does not contain a valid string representation of a date.</exception>
public static DateOnly ParseExact(
string s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string format,
[@StringSyntax(StringSyntax.DateOnlyFormat)] string format,
IFormatProvider? provider,
DateTimeStyles style = DateTimeStyles.None
)
Expand All @@ -601,7 +601,7 @@ public static DateOnly ParseExact(
/// <exception cref="FormatException"><paramref name="s"/> does not contain a valid string representation of a date.</exception>
public static DateOnly ParseExact(
string s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string[] formats
[@StringSyntax(StringSyntax.DateOnlyFormat)] string[] formats
) => ParseExact(s, formats, null, DateTimeStyles.None);

/// <summary>
Expand All @@ -618,7 +618,7 @@ public static DateOnly ParseExact(
/// <exception cref="FormatException"><paramref name="s"/> does not contain a valid string representation of a date.</exception>
public static DateOnly ParseExact(
string s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string[] formats,
[@StringSyntax(StringSyntax.DateOnlyFormat)] string[] formats,
IFormatProvider? provider,
DateTimeStyles style = DateTimeStyles.None
)
Expand Down Expand Up @@ -686,7 +686,7 @@ out DateOnly result
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
ReadOnlySpan<char> s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] ReadOnlySpan<char> format,
[@StringSyntax(StringSyntax.DateOnlyFormat)] ReadOnlySpan<char> format,
out DateOnly result
) => TryParseExact(s, format, null, DateTimeStyles.None, out result);

Expand All @@ -707,7 +707,7 @@ out DateOnly result
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
ReadOnlySpan<char> s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] ReadOnlySpan<char> format,
[@StringSyntax(StringSyntax.DateOnlyFormat)] ReadOnlySpan<char> format,
IFormatProvider? provider,
DateTimeStyles style,
out DateOnly result
Expand All @@ -731,7 +731,7 @@ out DateOnly result
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
ReadOnlySpan<char> s,
[NotNullWhen(true), @StringSyntax(StringSyntaxAttribute.DateOnlyFormat)]
[NotNullWhen(true), @StringSyntax(StringSyntax.DateOnlyFormat)]
string?[]? formats,
out DateOnly result
) => TryParseExact(s, formats, null, DateTimeStyles.None, out result);
Expand All @@ -752,7 +752,7 @@ out DateOnly result
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
ReadOnlySpan<char> s,
[NotNullWhen(true), @StringSyntax(StringSyntaxAttribute.DateOnlyFormat)]
[NotNullWhen(true), @StringSyntax(StringSyntax.DateOnlyFormat)]
string?[]? formats,
IFormatProvider? provider,
DateTimeStyles style,
Expand Down Expand Up @@ -821,7 +821,7 @@ out DateOnly result
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
ReadOnlySpan<char> s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] ReadOnlySpan<char> format,
[@StringSyntax(StringSyntax.DateOnlyFormat)] ReadOnlySpan<char> format,
out DateOnly result
) => TryParseExact(s, format, null, DateTimeStyles.None, out result);

Expand All @@ -842,7 +842,7 @@ out DateOnly result
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
ReadOnlySpan<char> s,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] ReadOnlySpan<char> format,
[@StringSyntax(StringSyntax.DateOnlyFormat)] ReadOnlySpan<char> format,
IFormatProvider? provider,
DateTimeStyles style,
out DateOnly result
Expand Down Expand Up @@ -872,7 +872,7 @@ out var dateTime
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
ReadOnlySpan<char> s,
[NotNullWhen(true), @StringSyntax(StringSyntaxAttribute.DateOnlyFormat)]
[NotNullWhen(true), @StringSyntax(StringSyntax.DateOnlyFormat)]
string?[]? formats,
out DateOnly result
) => TryParseExact(s, formats, null, DateTimeStyles.None, out result);
Expand All @@ -893,7 +893,7 @@ out DateOnly result
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
ReadOnlySpan<char> s,
[NotNullWhen(true), @StringSyntax(StringSyntaxAttribute.DateOnlyFormat)]
[NotNullWhen(true), @StringSyntax(StringSyntax.DateOnlyFormat)]
string?[]? formats,
IFormatProvider? provider,
DateTimeStyles style,
Expand Down Expand Up @@ -963,7 +963,7 @@ out DateOnly result
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
[NotNullWhen(true)] string? s,
[NotNullWhen(true), @StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string? format,
[NotNullWhen(true), @StringSyntax(StringSyntax.DateOnlyFormat)] string? format,
out DateOnly result
) => TryParseExact(s, format, null, DateTimeStyles.None, out result);

Expand All @@ -983,7 +983,7 @@ out DateOnly result
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
[NotNullWhen(true)] string? s,
[NotNullWhen(true), @StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string? format,
[NotNullWhen(true), @StringSyntax(StringSyntax.DateOnlyFormat)] string? format,
IFormatProvider? provider,
DateTimeStyles style,
out DateOnly result
Expand All @@ -1006,7 +1006,7 @@ out DateOnly result
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
[NotNullWhen(true)] string? s,
[NotNullWhen(true), @StringSyntax(StringSyntaxAttribute.DateOnlyFormat)]
[NotNullWhen(true), @StringSyntax(StringSyntax.DateOnlyFormat)]
string?[]? formats,
out DateOnly result
) => TryParseExact(s, formats, null, DateTimeStyles.None, out result);
Expand All @@ -1026,7 +1026,7 @@ out DateOnly result
/// otherwise, <see langword="false"/>.</returns>
public static bool TryParseExact(
[NotNullWhen(true)] string? s,
[NotNullWhen(true), @StringSyntax(StringSyntaxAttribute.DateOnlyFormat)]
[NotNullWhen(true), @StringSyntax(StringSyntax.DateOnlyFormat)]
string?[]? formats,
IFormatProvider? provider,
DateTimeStyles style,
Expand Down Expand Up @@ -1063,7 +1063,7 @@ out DateOnly result
/// <param name="format">A standard or custom date format string.</param>
/// <returns>A string representation of value of the current <see cref="DateOnly"/> object as specified by <paramref name="format"/>.</returns>
public string ToString(
[@StringSyntax(@StringSyntaxAttribute.DateOnlyFormat)] string? format
[@StringSyntax(StringSyntax.DateOnlyFormat)] string? format
)
{
if (string.IsNullOrEmpty(format))
Expand All @@ -1089,7 +1089,7 @@ public string ToString(
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>A string representation of value of the current <see cref="DateOnly"/> object as specified by format and provider.</returns>
public string ToString(
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string? format,
[@StringSyntax(StringSyntax.DateOnlyFormat)] string? format,
IFormatProvider? provider
)
{
Expand Down Expand Up @@ -1117,7 +1117,7 @@ public string ToString(
public bool TryFormat(
Span<char> destination,
out int charsWritten,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)]
[@StringSyntax(StringSyntax.DateOnlyFormat)]
ReadOnlySpan<char> format = default(ReadOnlySpan<char>),
IFormatProvider? provider = null
)
Expand All @@ -1144,7 +1144,7 @@ public bool TryFormat(
public bool TryFormat(
Span<char> destination,
out int charsWritten,
[@StringSyntax(StringSyntaxAttribute.DateOnlyFormat)]
[@StringSyntax(StringSyntax.DateOnlyFormat)]
ReadOnlySpan<char> format = default(ReadOnlySpan<char>),
IFormatProvider? provider = null
)
Expand Down
Loading

0 comments on commit 5e49aa5

Please sign in to comment.