From 2cbc2b2abb0e60160b54b9932da42af510476b63 Mon Sep 17 00:00:00 2001 From: "David G. Moore, Jr." Date: Wed, 27 Dec 2023 05:16:39 -0500 Subject: [PATCH] Polyfills --- .vscode/settings.json | 6 +- All/Dgmjr.Types.csproj | 31 ++++++++ Dgmjr.Types.csproj | 31 -------- Enumerations | 2 +- Extensions | 2 +- InterfaceGenerator | 2 +- Primitives | 2 +- RegexDtoGenerator | 2 +- .../DoesNotReturnIfAttribute.cs | 17 +++++ .../NotNullAttribute.cs | 24 +++++++ .../StringSyntaxAttribute.cs | 72 +++++++++++++++++++ ...tem.Private.CoreLib.Polyfills.Constants.cs | 17 +++++ .../System.Private.CoreLib.Polyfills.props | 12 +++- .../System.Private.CoreLib.Polyfills.targets | 16 +++++ .../IsExternalInit.cs | 7 +- 15 files changed, 199 insertions(+), 44 deletions(-) create mode 100644 All/Dgmjr.Types.csproj delete mode 100644 Dgmjr.Types.csproj create mode 100644 System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/DoesNotReturnIfAttribute.cs create mode 100644 System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/NotNullAttribute.cs create mode 100644 System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/StringSyntaxAttribute.cs create mode 100644 System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.Constants.cs create mode 100644 System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.targets diff --git a/.vscode/settings.json b/.vscode/settings.json index 2a95835..8feb137 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,9 @@ "activityBar.background": "#5B1207", "titleBar.activeBackground": "#80190A", "titleBar.activeForeground": "#FFFCFB" + }, + "sonarlint.connectedMode.project": { + "connectionId": "dgmjr-io", + "projectKey": "dgmjr-io_Dgmjr.Types" } -} \ No newline at end of file +} diff --git a/All/Dgmjr.Types.csproj b/All/Dgmjr.Types.csproj new file mode 100644 index 0000000..fa11e3a --- /dev/null +++ b/All/Dgmjr.Types.csproj @@ -0,0 +1,31 @@ + + + + + + netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0 + + + + + + + + + + + + + + + diff --git a/Dgmjr.Types.csproj b/Dgmjr.Types.csproj deleted file mode 100644 index fbac0df..0000000 --- a/Dgmjr.Types.csproj +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0 - - - - - - - - - - - - - - - diff --git a/Enumerations b/Enumerations index 8ffb153..4159f70 160000 --- a/Enumerations +++ b/Enumerations @@ -1 +1 @@ -Subproject commit 8ffb1531f0f34008207f3cfbabe4d98e433b1cf4 +Subproject commit 4159f7081cc386611bdba39c1cade713175d2a05 diff --git a/Extensions b/Extensions index 26e9af0..7156781 160000 --- a/Extensions +++ b/Extensions @@ -1 +1 @@ -Subproject commit 26e9af0f4688af7a783410c58d957a33c1799a50 +Subproject commit 715678129e01dec25fa9c3ffba704a0bff507d84 diff --git a/InterfaceGenerator b/InterfaceGenerator index 34b96b4..d1c95b4 160000 --- a/InterfaceGenerator +++ b/InterfaceGenerator @@ -1 +1 @@ -Subproject commit 34b96b4d13bced3e8a43cf25b58ba2994c2b29d1 +Subproject commit d1c95b42c3c2874c699f8801ba4c72e1ce61e0ea diff --git a/Primitives b/Primitives index 7ff0631..8b6d48e 160000 --- a/Primitives +++ b/Primitives @@ -1 +1 @@ -Subproject commit 7ff06316f3ac39e4f998b2670e96b3906dc8c0c9 +Subproject commit 8b6d48e1cb065e843ec67facb6acd5c21e860f33 diff --git a/RegexDtoGenerator b/RegexDtoGenerator index 59fa55c..8935ec8 160000 --- a/RegexDtoGenerator +++ b/RegexDtoGenerator @@ -1 +1 @@ -Subproject commit 59fa55ccf7f575c0502d00fa09fd7b72a7f951e2 +Subproject commit 8935ec8cb8e1de531a0139eef86dd47738ebec02 diff --git a/System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/DoesNotReturnIfAttribute.cs b/System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/DoesNotReturnIfAttribute.cs new file mode 100644 index 0000000..ca6cafb --- /dev/null +++ b/System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/DoesNotReturnIfAttribute.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Diagnostics.CodeAnalysis; + +internal sealed class DoesNotReturnIfAttribute : Attribute +{ + /// Initializes the attribute with the specified parameter value. + /// + /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to + /// the associated parameter matches this value. + /// + public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; + + /// Gets the condition parameter value. + public bool ParameterValue { get; } +} diff --git a/System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/NotNullAttribute.cs b/System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/NotNullAttribute.cs new file mode 100644 index 0000000..a93d888 --- /dev/null +++ b/System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/NotNullAttribute.cs @@ -0,0 +1,24 @@ +// https://stackoverflow.com/questions/61573959/how-to-resolve-error-notnullwhen-attribute-is-inaccessible-due-to-its-protectio + +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Specifies that when a method returns , the +/// parameter will not be null even if the corresponding type allows it. +/// +[AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +internal sealed class NotNullAttribute : Attribute +{ + /// + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method + /// returns this value, the associated parameter will not be null. + /// + public NotNullAttribute(bool returnValue) => ReturnValue = returnValue; + + /// + /// Gets the return value condition. + /// + public bool ReturnValue { get; } +} diff --git a/System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/StringSyntaxAttribute.cs b/System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/StringSyntaxAttribute.cs new file mode 100644 index 0000000..b6ced2c --- /dev/null +++ b/System.Private.CoreLib.Polyfills/System.Diagnostics.CodeAnalysis/StringSyntaxAttribute.cs @@ -0,0 +1,72 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Diagnostics.CodeAnalysis; + +/// Specifies the syntax used in a string. +[AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, + AllowMultiple = false, + Inherited = false +)] +internal sealed class StringSyntaxAttribute : Attribute +{ + /// Initializes the with the identifier of the syntax used. + /// The syntax identifier. + public StringSyntaxAttribute(string syntax) + { + Syntax = syntax; + Arguments = Array.Empty(); + } + + /// Initializes the with the identifier of the syntax used. + /// The syntax identifier. + /// Optional arguments associated with the specific syntax employed. + public StringSyntaxAttribute(string syntax, params object?[] arguments) + { + Syntax = syntax; + Arguments = arguments; + } + + /// Gets the identifier of the syntax used. + public string Syntax { get; } + + /// Optional arguments associated with the specific syntax employed. + public object?[] Arguments { get; } + + /// The syntax identifier for strings containing composite formats for string formatting. + public const string CompositeFormat = nameof(CompositeFormat); + + /// The syntax identifier for strings containing date format specifiers. + public const string DateOnlyFormat = nameof(DateOnlyFormat); + + /// The syntax identifier for strings containing date and time format specifiers. + public const string DateTimeFormat = nameof(DateTimeFormat); + + /// The syntax identifier for strings containing format specifiers. + public const string EnumFormat = nameof(EnumFormat); + + /// The syntax identifier for strings containing format specifiers. + public const string GuidFormat = nameof(GuidFormat); + + /// The syntax identifier for strings containing JavaScript Object Notation (JSON). + public const string Json = nameof(Json); + + /// The syntax identifier for strings containing numeric format specifiers. + public const string NumericFormat = nameof(NumericFormat); + + /// The syntax identifier for strings containing regular expressions. + public const string Regex = nameof(Regex); + + /// The syntax identifier for strings containing time format specifiers. + public const string TimeOnlyFormat = nameof(TimeOnlyFormat); + + /// The syntax identifier for strings containing format specifiers. + public const string TimeSpanFormat = nameof(TimeSpanFormat); + + /// The syntax identifier for strings containing URIs. + public const string Uri = nameof(Uri); + + /// The syntax identifier for strings containing XML. + public const string Xml = nameof(Xml); +} diff --git a/System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.Constants.cs b/System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.Constants.cs new file mode 100644 index 0000000..3c61908 --- /dev/null +++ b/System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.Constants.cs @@ -0,0 +1,17 @@ +namespace System.Private.CoreLib.Polyfills; + +public class Constants +{ + public const string NET8_0_OR_GREATER = nameof(NET8_0_OR_GREATER); + public const string NET7_0_OR_GREATER = nameof(NET7_0_OR_GREATER); + public const string NET6_0_OR_GREATER = nameof(NET6_0_OR_GREATER); + public const string NETSTANDARD = nameof(NETSTANDARD); + public const string NETSTANDARD2_1_OR_GREATER = nameof(NETSTANDARD2_1_OR_GREATER); + public const string NETSTANDARD2_0_OR_GREATER = nameof(NETSTANDARD2_0_OR_GREATER); + public const string NOT_NET8_0_OR_GREATER = nameof(NOT_NET8_0_OR_GREATER); + public const string NOT_NET7_0_OR_GREATER = nameof(NOT_NET7_0_OR_GREATER); + public const string NOT_NET6_0_OR_GREATER = nameof(NOT_NET6_0_OR_GREATER); + public const string NOT_NETSTANDARD = nameof(NOT_NETSTANDARD); + public const string NOT_NETSTANDARD2_1_OR_GREATER = nameof(NOT_NETSTANDARD2_1_OR_GREATER); + public const string NOT_NETSTANDARD2_0_OR_GREATER = nameof(NOT_NETSTANDARD2_0_OR_GREATER); +} diff --git a/System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.props b/System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.props index b7624aa..965ddfc 100644 --- a/System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.props +++ b/System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.props @@ -1,6 +1,16 @@ + - + + + diff --git a/System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.targets b/System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.targets new file mode 100644 index 0000000..78b6ad4 --- /dev/null +++ b/System.Private.CoreLib.Polyfills/System.Private.CoreLib.Polyfills.targets @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/System.Private.CoreLib.Polyfills/System.Runtime.CompilerServices/IsExternalInit.cs b/System.Private.CoreLib.Polyfills/System.Runtime.CompilerServices/IsExternalInit.cs index 08cb489..696a072 100644 --- a/System.Private.CoreLib.Polyfills/System.Runtime.CompilerServices/IsExternalInit.cs +++ b/System.Private.CoreLib.Polyfills/System.Runtime.CompilerServices/IsExternalInit.cs @@ -10,10 +10,5 @@ namespace System.Runtime.CompilerServices /// should not be used by developers in source code. /// [EditorBrowsable(EditorBrowsableState.Never)] -#if SYSTEM_PRIVATE_CORELIB - public -#else - internal -#endif - static class IsExternalInit { } + internal static class IsExternalInit { } }