Skip to content

Commit

Permalink
Fixing the System.Private.CoreLib.Polyfills project
Browse files Browse the repository at this point in the history
  • Loading branch information
dgmjr committed Jan 10, 2024
1 parent 2cbc2b2 commit a45d3b7
Show file tree
Hide file tree
Showing 24 changed files with 219 additions and 84 deletions.
2 changes: 1 addition & 1 deletion ComponentModel
2 changes: 1 addition & 1 deletion Enumerations
2 changes: 1 addition & 1 deletion Extensions
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace System.Diagnostics.CodeAnalysis;

/// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary>
[AttributeUsage(
AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property,
Inherited = false
)]
[Conditional(global::System.Private.CoreLib.Polyfills.Constants.NOTNETSTANDARD21ORGREATER)]
internal sealed class AllowNullAttribute : Attribute { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace System.Diagnostics.CodeAnalysis;

/// <summary>Specifies that null is disallowed as an input even if the corresponding type allows it.</summary>
[AttributeUsage(
AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property,
Inherited = false
)]
[Conditional(global::System.Private.CoreLib.Polyfills.Constants.NOTNETSTANDARD21ORGREATER)]
internal sealed class DisallowNullAttribute : Attribute { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace System.Diagnostics.CodeAnalysis;

/// <summary>Applied to a method that will never return under any circumstance.</summary>
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
[Conditional(global::System.Private.CoreLib.Polyfills.Constants.NOTNETSTANDARD21ORGREATER)]
internal sealed class DoesNotReturnAttribute : Attribute { }
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// 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;

/// <summary>Specifies that the method will not return if the associated Boolean parameter is passed the specified value.</summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class DoesNotReturnIfAttribute : Attribute
{
/// <summary>Initializes the attribute with the specified parameter value.</summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace System.Diagnostics.CodeAnalysis;

/// <summary>Specifies that an output may be null even if the corresponding type disallows it.</summary>
[AttributeUsage(
AttributeTargets.Field
| AttributeTargets.Parameter
| AttributeTargets.Property
| AttributeTargets.ReturnValue,
Inherited = false
)]
[Conditional(global::System.Private.CoreLib.Polyfills.Constants.NOTNETSTANDARD21ORGREATER)]
internal sealed class MaybeNullAttribute : Attribute { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace System.Diagnostics.CodeAnalysis;

/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter may be null even if the corresponding type disallows it.</summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[Conditional(global::System.Private.CoreLib.Polyfills.Constants.NOTNETSTANDARD21ORGREATER)]
internal sealed class MaybeNullWhenAttribute : Attribute
{
/// <summary>Initializes the attribute with the specified return value condition.</summary>
/// <param name="returnValue">
/// The return value condition. If the method returns this value, the associated parameter may be null.
/// </param>
public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;

/// <summary>Gets the return value condition.</summary>
public bool ReturnValue { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace System.Diagnostics.CodeAnalysis;

/// <summary>Specifies that the method or property will ensure that the listed field and property members have not-null values.</summary>
[AttributeUsage(
AttributeTargets.Method | AttributeTargets.Property,
Inherited = false,
AllowMultiple = true
)]
[Conditional(global::System.Private.CoreLib.Polyfills.Constants.NOTNETSTANDARD21ORGREATER)]
internal sealed class MemberNotNullAttribute : Attribute
{
/// <summary>Initializes the attribute with a field or property member.</summary>
/// <param name="member">
/// The field or property member that is promised to be not-null.
/// </param>
public MemberNotNullAttribute(string member) => Members = new[] { member };

/// <summary>Initializes the attribute with the list of field and property members.</summary>
/// <param name="members">
/// The list of field and property members that are promised to be not-null.
/// </param>
public MemberNotNullAttribute(params string[] members) => Members = members;

/// <summary>Gets field or property member names.</summary>
public string[] Members { get; }
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
// https://stackoverflow.com/questions/61573959/how-to-resolve-error-notnullwhen-attribute-is-inaccessible-due-to-its-protectio

namespace System.Diagnostics.CodeAnalysis;

/// <summary>
/// Specifies that when a method returns <see cref="ReturnValue"/>, the
/// parameter will not be null even if the corresponding type allows it.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class NotNullAttribute : Attribute
/// <summary>Specifies that an output will not be null even if the corresponding type allows it. Specifies that an input argument was not null when the call returns.</summary>
[AttributeUsage(
AttributeTargets.Field
| AttributeTargets.Parameter
| AttributeTargets.Property
| AttributeTargets.ReturnValue,
Inherited = false
)]
[Conditional(global::System.Private.CoreLib.Polyfills.Constants.NOTNETSTANDARD21ORGREATER)]
internal sealed class NotNullAttribute() : Attribute
{
/// <summary>
/// Initializes the attribute with the specified return value condition.
/// </summary>
/// <param name="returnValue">The return value condition. If the method
/// returns this value, the associated parameter will not be null.
/// </param>
public NotNullAttribute(bool returnValue) => ReturnValue = returnValue;
public NotNullAttribute(bool returnValue)
: this() => ReturnValue = returnValue;

/// <summary>
/// Gets the return value condition.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace System.Diagnostics.CodeAnalysis;

/// <summary>Specifies that the output will be non-null if the named parameter is non-null.</summary>
[AttributeUsage(
AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue,
AllowMultiple = true,
Inherited = false
)]
[Conditional(global::System.Private.CoreLib.Polyfills.Constants.NOTNETSTANDARD21ORGREATER)]
internal sealed class NotNullIfNotNullAttribute : Attribute
{
/// <summary>Initializes the attribute with the associated parameter name.</summary>
/// <param name="parameterName">
/// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null.
/// </param>
public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName;

/// <summary>Gets the associated parameter name.</summary>
public string ParameterName { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace System.Diagnostics.CodeAnalysis;

/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter will not be null even if the corresponding type allows it.</summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[Conditional(global::System.Private.CoreLib.Polyfills.Constants.NOTNETSTANDARD21ORGREATER)]
internal sealed class NotNullWhenAttribute : Attribute
{
/// <summary>Initializes the attribute with the specified return value condition.</summary>
/// <param name="returnValue">
/// The return value condition. If the method returns this value, the associated parameter will not be null.
/// </param>
public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;

/// <summary>Gets the return value condition.</summary>
public bool ReturnValue { get; }
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace System.Diagnostics.CodeAnalysis;

[System.AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
[global::System.AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute(params string[] members) : Attribute
{
public string[] Members { get; } = members;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace System.Diagnostics.CodeAnalysis;
AllowMultiple = false,
Inherited = false
)]
[Conditional(global::System.Private.CoreLib.Polyfills.Constants.NOTNET70ORGREATER)]
internal sealed class StringSyntaxAttribute : Attribute
{
/// <summary>Initializes the <see cref="StringSyntaxAttribute"/> with the identifier of the syntax used.</summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace System.Diagnostics.CodeAnalysis;

/// <summary>Specifies that the method or property will ensure that the listed field and property members have not-null values when returning with the specified return value condition.</summary>
[AttributeUsage(
AttributeTargets.Method | AttributeTargets.Property,
Inherited = false,
AllowMultiple = true
)]
[Conditional(global::System.Private.CoreLib.Polyfills.Constants.NOTNETSTANDARD21ORGREATER)]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
/// <summary>Initializes the attribute with the specified return value condition and a field or property member.</summary>
/// <param name="returnValue">
/// The return value condition. If the method returns this value, the associated parameter will not be null.
/// </param>
/// <param name="member">
/// The field or property member that is promised to be not-null.
/// </param>
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new[] { member };
}

/// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary>
/// <param name="returnValue">
/// The return value condition. If the method returns this value, the associated parameter will not be null.
/// </param>
/// <param name="members">
/// The list of field and property members that are promised to be not-null.
/// </param>
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}

/// <summary>Gets the return value condition.</summary>
public bool ReturnValue { get; }

/// <summary>Gets field or property member names.</summary>
public string[] Members { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ 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);
public const string NOTNET80ORGREATER = nameof(NOTNET80ORGREATER);
public const string NOTNET70ORGREATER = nameof(NOTNET70ORGREATER);
public const string NOTNET60ORGREATER = nameof(NOTNET60ORGREATER);
public const string NOTNETSTANDARD = nameof(NOTNETSTANDARD);
public const string NOTNETSTANDARD21ORGREATER = nameof(NOTNETSTANDARD21ORGREATER);
public const string NOTNETSTANDARD20ORGREATER = nameof(NOTNETSTANDARD20ORGREATER);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageFile Include="./**/*.cs" Except="$(IntermediateOutputPath)**/*.cs" PackagePath="ContentFiles/%(RecursiveDir)%(Filename)%(Extension)" />
<PackageFile Include="README.md" PackagePath="%(Filename)%(Extension)" />
<PackageFile Remove="$(IntermediateOutputPath)**/*" />
<Compile Remove="@Compile)" />
<Compile Remove="@(Compile)" />
</ItemGroup>
<!-- Dont' do this one -->
<Target Name="SourceFilesProjectOutputGroup" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<Project>
<!-- <PropertyGroup>
<DefineConstants Condition="!$(DeclareConstants.Contains('NET8_0_OR_GREATER'))">$(DefineConstants);NOT_NET8_0_OR_GREATER</DefineConstants>
<DefineConstants Condition="!$(DeclareConstants.Contains('NET7_0_OR_GREATER'))">$(DefineConstants);NOT_NET7_0_OR_GREATER</DefineConstants>
<DefineConstants Condition="!$(DeclareConstants.Contains('NET6_0_OR_GREATER'))">$(DefineConstants);NOT_NET6_0_OR_GREATER</DefineConstants>
<DefineConstants Condition="!$(DeclareConstants.Contains('NETSTANDARD'))">$(DefineConstants);NOT_NETSTANDARD</DefineConstants>
<DefineConstants Condition="!$(DeclareConstants.Contains('NETSTANDARD2_0_OR_GREATER'))">$(DefineConstants);NOT_NETSTANDARD2_0_OR_GREATER</DefineConstants>
<DefineConstants Condition="!$(DeclareConstants.Contains('NETSTANDARD2_1_OR_GREATER'))">$(DefineConstants);NOT_NETSTANDARD2_1_OR_GREATER</DefineConstants>
</PropertyGroup> -->
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)../ContentFiles/**/*.cs" Condition="!$(DefineConstants.Contains('NET7_0_OR_GREATER')) And '$(MSBuildProjectName)' != 'System.Private.CoreLib.Polyfills'" />
<Compile Remove="$(MSBuildThisFileDirectory)../ContentFiles/**/*.cs" Condition="$(DefineConstants.Contains('NET7_0_OR_GREATER'))" />
<PropertyGroup>
<DefineConstants Condition="!$(DefineConstants.Contains('NET8_0_OR_GREATER'))">$(DefineConstants);NOTNET80ORGREATER</DefineConstants>
<DefineConstants Condition="!$(DefineConstants.Contains('NET7_0_OR_GREATER'))">$(DefineConstants);NOTNET70ORGREATER</DefineConstants>
<DefineConstants Condition="!$(DefineConstants.Contains('NET6_0_OR_GREATER'))">$(DefineConstants);NOTNET60ORGREATER</DefineConstants>
<DefineConstants Condition="!$(DefineConstants.Contains('NETSTANDARD'))">$(DefineConstants);NOT_NETSTANDARD</DefineConstants>
<DefineConstants Condition="!$(DefineConstants.Contains('NETSTANDARD2_0_OR_GREATER'))">$(DefineConstants);NOTNETSTANDARD20ORGREATER</DefineConstants>
<DefineConstants Condition="!$(DefineConstants.Contains('NETSTANDARD2_1_OR_GREATER'))">$(DefineConstants);NOTNETSTANDARD21ORGREATER</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(MSBuildProjectName)' != 'System.Private.CoreLib.Polyfills'">
<Compile Include="$(MSBuildThisFileDirectory)../ContentFiles/**/*.cs" Link="Polyfills/%(Filename)%(Extension)" Pack="false" />
<Using Include="System.Runtime.CompilerServices" />
<Using Include="System.Diagnostics.CodeAnalysis.StringSyntaxAttribute" Alias="StringSyntax" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
Microsoft Visual Studio Solution File, Format Version 12.00
#
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B283EBC2-E01F-412D-9339-FD56EF114549}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B283EBC2-E01F-412D-9339-FD56EF114549}"
ProjectSection(SolutionItems) = preProject
..\..\..\Directory.Build.props = ..\..\..\Directory.Build.props
..\..\..\Directory.Build.targets = ..\..\..\Directory.Build.targets
..\..\..\global.json = ..\..\..\global.json
..\..\..\Packages\Versions.Local.props = ..\..\..\Packages\Versions.Local.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Private.CoreLib.Polyfills", "System.Private.CoreLib.Polyfills.csproj", "{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Local|Any CPU = Local|Any CPU
Expand All @@ -20,18 +17,6 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Local|Any CPU.ActiveCfg = Local|Any CPU
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Local|Any CPU.Build.0 = Local|Any CPU
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Testing|Any CPU.Build.0 = Testing|Any CPU
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Staging|Any CPU.Build.0 = Staging|Any CPU
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Production|Any CPU.ActiveCfg = Local|Any CPU
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Production|Any CPU.Build.0 = Local|Any CPU
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D15EFD5F-3FAA-4EE9-A1E1-65EE9B429DB1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading

0 comments on commit a45d3b7

Please sign in to comment.