Skip to content

Commit adcdf43

Browse files
authored
Merge pull request #2478 from mhutch/update-polyfills
Update polyfills
2 parents 2faedc5 + 4f6931d commit adcdf43

File tree

11 files changed

+235
-83
lines changed

11 files changed

+235
-83
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// adapted from: https://github.com/dotnet/aspnetcore/blob/404d81767784552b0a148cb8c437332ebe726ae9/src/Shared/CodeAnalysis/DynamicallyAccessedMemberTypes.cs
22

3-
#if !NET6_0_OR_GREATER
3+
#if !NET5_0_OR_GREATER
44
// Licensed to the .NET Foundation under one or more agreements.
55
// The .NET Foundation licenses this file to you under the MIT license.
66

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// adapted from: https://github.com/dotnet/aspnetcore/blob/404d81767784552b0a148cb8c437332ebe726ae9/src/Shared/CodeAnalysis/DynamicallyAccessedMembersAttribute.cs#L29
22

3-
#if !NET6_0_OR_GREATER
3+
#if !NET5_0_OR_GREATER
44
// Licensed to the .NET Foundation under one or more agreements.
55
// The .NET Foundation licenses this file to you under the MIT license.
66

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Diagnostics.CodeAnalysis
5+
{
6+
#if !NETCOREAPP3_0_OR_GREATER
7+
/// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary>
8+
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
9+
internal sealed class AllowNullAttribute : Attribute
10+
{ }
11+
12+
/// <summary>Specifies that null is disallowed as an input even if the corresponding type allows it.</summary>
13+
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
14+
internal sealed class DisallowNullAttribute : Attribute
15+
{ }
16+
17+
/// <summary>Specifies that an output may be null even if the corresponding type disallows it.</summary>
18+
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
19+
internal sealed class MaybeNullAttribute : Attribute
20+
{ }
21+
22+
/// <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>
23+
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
24+
internal sealed class NotNullAttribute : Attribute
25+
{ }
26+
27+
/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter may be null even if the corresponding type disallows it.</summary>
28+
[AttributeUsage (AttributeTargets.Parameter, Inherited = false)]
29+
internal sealed class MaybeNullWhenAttribute : Attribute
30+
{
31+
/// <summary>Initializes the attribute with the specified return value condition.</summary>
32+
/// <param name="returnValue">
33+
/// The return value condition. If the method returns this value, the associated parameter may be null.
34+
/// </param>
35+
public MaybeNullWhenAttribute (bool returnValue) => ReturnValue = returnValue;
36+
37+
/// <summary>Gets the return value condition.</summary>
38+
public bool ReturnValue { get; }
39+
}
40+
41+
/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter will not be null even if the corresponding type allows it.</summary>
42+
[AttributeUsage (AttributeTargets.Parameter, Inherited = false)]
43+
internal sealed class NotNullWhenAttribute : Attribute
44+
{
45+
/// <summary>Initializes the attribute with the specified return value condition.</summary>
46+
/// <param name="returnValue">
47+
/// The return value condition. If the method returns this value, the associated parameter will not be null.
48+
/// </param>
49+
public NotNullWhenAttribute (bool returnValue) => ReturnValue = returnValue;
50+
51+
/// <summary>Gets the return value condition.</summary>
52+
public bool ReturnValue { get; }
53+
}
54+
55+
/// <summary>Specifies that the output will be non-null if the named parameter is non-null.</summary>
56+
[AttributeUsage (AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
57+
internal sealed class NotNullIfNotNullAttribute : Attribute
58+
{
59+
/// <summary>Initializes the attribute with the associated parameter name.</summary>
60+
/// <param name="parameterName">
61+
/// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null.
62+
/// </param>
63+
public NotNullIfNotNullAttribute (string parameterName) => ParameterName = parameterName;
64+
65+
/// <summary>Gets the associated parameter name.</summary>
66+
public string ParameterName { get; }
67+
}
68+
69+
/// <summary>Applied to a method that will never return under any circumstance.</summary>
70+
[AttributeUsage (AttributeTargets.Method, Inherited = false)]
71+
internal sealed class DoesNotReturnAttribute : Attribute
72+
{ }
73+
74+
/// <summary>Specifies that the method will not return if the associated Boolean parameter is passed the specified value.</summary>
75+
[AttributeUsage (AttributeTargets.Parameter, Inherited = false)]
76+
internal sealed class DoesNotReturnIfAttribute : Attribute
77+
{
78+
/// <summary>Initializes the attribute with the specified parameter value.</summary>
79+
/// <param name="parameterValue">
80+
/// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to
81+
/// the associated parameter matches this value.
82+
/// </param>
83+
public DoesNotReturnIfAttribute (bool parameterValue) => ParameterValue = parameterValue;
84+
85+
/// <summary>Gets the condition parameter value.</summary>
86+
public bool ParameterValue { get; }
87+
}
88+
89+
#endif
90+
#if !NET5_0_OR_GREATER
91+
92+
/// <summary>Specifies that the method or property will ensure that the listed field and property members have not-null values.</summary>
93+
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
94+
internal sealed class MemberNotNullAttribute : Attribute
95+
{
96+
/// <summary>Initializes the attribute with a field or property member.</summary>
97+
/// <param name="member">
98+
/// The field or property member that is promised to be not-null.
99+
/// </param>
100+
public MemberNotNullAttribute (string member) => Members = new[] { member };
101+
102+
/// <summary>Initializes the attribute with the list of field and property members.</summary>
103+
/// <param name="members">
104+
/// The list of field and property members that are promised to be not-null.
105+
/// </param>
106+
public MemberNotNullAttribute (params string[] members) => Members = members;
107+
108+
/// <summary>Gets field or property member names.</summary>
109+
public string[] Members { get; }
110+
}
111+
112+
/// <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>
113+
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
114+
internal sealed class MemberNotNullWhenAttribute : Attribute
115+
{
116+
/// <summary>Initializes the attribute with the specified return value condition and a field or property member.</summary>
117+
/// <param name="returnValue">
118+
/// The return value condition. If the method returns this value, the associated parameter will not be null.
119+
/// </param>
120+
/// <param name="member">
121+
/// The field or property member that is promised to be not-null.
122+
/// </param>
123+
public MemberNotNullWhenAttribute (bool returnValue, string member)
124+
{
125+
ReturnValue = returnValue;
126+
Members = new[] { member };
127+
}
128+
129+
/// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary>
130+
/// <param name="returnValue">
131+
/// The return value condition. If the method returns this value, the associated parameter will not be null.
132+
/// </param>
133+
/// <param name="members">
134+
/// The list of field and property members that are promised to be not-null.
135+
/// </param>
136+
public MemberNotNullWhenAttribute (bool returnValue, params string[] members)
137+
{
138+
ReturnValue = returnValue;
139+
Members = members;
140+
}
141+
142+
/// <summary>Gets the return value condition.</summary>
143+
public bool ReturnValue { get; }
144+
145+
/// <summary>Gets field or property member names.</summary>
146+
public string[] Members { get; }
147+
}
148+
#endif
149+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Diagnostics.CodeAnalysis
5+
{
6+
#if !NET7_0_OR_GREATER
7+
/// <summary>Specifies the syntax used in a string.</summary>
8+
[AttributeUsage (AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
9+
sealed class StringSyntaxAttribute : Attribute
10+
{
11+
/// <summary>Initializes the <see cref="StringSyntaxAttribute"/> with the identifier of the syntax used.</summary>
12+
/// <param name="syntax">The syntax identifier.</param>
13+
public StringSyntaxAttribute(string syntax)
14+
{
15+
Syntax = syntax;
16+
Arguments = Array.Empty<object?>();
17+
}
18+
19+
/// <summary>Initializes the <see cref="StringSyntaxAttribute"/> with the identifier of the syntax used.</summary>
20+
/// <param name="syntax">The syntax identifier.</param>
21+
/// <param name="arguments">Optional arguments associated with the specific syntax employed.</param>
22+
public StringSyntaxAttribute(string syntax, params object?[] arguments)
23+
{
24+
Syntax = syntax;
25+
Arguments = arguments;
26+
}
27+
28+
/// <summary>Gets the identifier of the syntax used.</summary>
29+
public string Syntax { get; }
30+
31+
/// <summary>Optional arguments associated with the specific syntax employed.</summary>
32+
public object?[] Arguments { get; }
33+
34+
/// <summary>The syntax identifier for strings containing composite formats for string formatting.</summary>
35+
public const string CompositeFormat = nameof(CompositeFormat);
36+
37+
/// <summary>The syntax identifier for strings containing date format specifiers.</summary>
38+
public const string DateOnlyFormat = nameof(DateOnlyFormat);
39+
40+
/// <summary>The syntax identifier for strings containing date and time format specifiers.</summary>
41+
public const string DateTimeFormat = nameof(DateTimeFormat);
42+
43+
/// <summary>The syntax identifier for strings containing <see cref="Enum"/> format specifiers.</summary>
44+
public const string EnumFormat = nameof(EnumFormat);
45+
46+
/// <summary>The syntax identifier for strings containing <see cref="Guid"/> format specifiers.</summary>
47+
public const string GuidFormat = nameof(GuidFormat);
48+
49+
/// <summary>The syntax identifier for strings containing JavaScript Object Notation (JSON).</summary>
50+
public const string Json = nameof(Json);
51+
52+
/// <summary>The syntax identifier for strings containing numeric format specifiers.</summary>
53+
public const string NumericFormat = nameof(NumericFormat);
54+
55+
/// <summary>The syntax identifier for strings containing regular expressions.</summary>
56+
public const string Regex = nameof(Regex);
57+
58+
/// <summary>The syntax identifier for strings containing time format specifiers.</summary>
59+
public const string TimeOnlyFormat = nameof(TimeOnlyFormat);
60+
61+
/// <summary>The syntax identifier for strings containing <see cref="TimeSpan"/> format specifiers.</summary>
62+
public const string TimeSpanFormat = nameof(TimeSpanFormat);
63+
64+
/// <summary>The syntax identifier for strings containing URIs.</summary>
65+
public const string Uri = nameof(Uri);
66+
67+
/// <summary>The syntax identifier for strings containing XML.</summary>
68+
public const string Xml = nameof(Xml);
69+
}
70+
#endif
71+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// adapted from: https://github.com/dotnet/runtime/blob/a5159b1a8840632ad34cf59c5aaf77040cb6ceda/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/UnconditionalSuppressMessageAttribute.cs#L21
22

3-
#if !NET6_0_OR_GREATER
3+
#if !NET5_0_OR_GREATER
44

55

66
// Licensed to the .NET Foundation under one or more agreements.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
#if !NET5_0_OR_GREATER
5+
46
namespace System.Runtime.CompilerServices;
57

68
internal static class IsExternalInit
79
{
8-
}
10+
}
11+
12+
#endif

src/System.CommandLine.Extended/System.CommandLine.Extended.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<Compile Include="..\System.Diagnostics.CodeAnalysis.cs" Link="System.Diagnostics.CodeAnalysis\System.Diagnostics.CodeAnalysis.cs" />
2726
<Compile Include="VersionOption.cs" />
28-
<Compile Include="..\System.CommandLine\System.Diagnostics.CodeAnalysis\**\*.cs" Link="System.Diagnostics.CodeAnalysis\%(RecursiveDir)\%(Filename).%(Extension)" />
27+
<Compile Include="..\Common\Compat\**\*.cs" Link="Compat\%(RecursiveDir)%(Filename).%(Extension)" />
2928
</ItemGroup>
3029

3130
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">

src/System.CommandLine.Generator/System.CommandLine.Generator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<Compile Include="..\System.Diagnostics.CodeAnalysis.cs" Link="System.Diagnostics.CodeAnalysis.cs" />
17+
<Compile Include="..\Common\Compat\**\*.cs" Link="Compat\%(RecursiveDir)%(Filename).%(Extension)" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

src/System.CommandLine.Subsystems/System.CommandLine.Subsystems.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
<ProjectReference Include="..\System.CommandLine\System.CommandLine.csproj" />
1212
</ItemGroup>
1313

14+
<ItemGroup>
15+
<Compile Include="..\Common\Compat\**\*.cs" Link="Compat\%(RecursiveDir)%(Filename).%(Extension)" />
16+
</ItemGroup>
17+
1418
</Project>

src/System.CommandLine/System.CommandLine.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<Compile Include="..\System.Diagnostics.CodeAnalysis.cs" Link="System.Diagnostics.CodeAnalysis\System.Diagnostics.CodeAnalysis.cs" />
2726
<Compile Include="AliasSet.cs" />
2827
<Compile Include="ArgumentArity.cs" />
2928
<Compile Include="Binding\ArgumentConversionResult.cs" />
@@ -66,7 +65,7 @@
6665
<Compile Include="Parsing\CliValueResult.cs" />
6766
<Compile Include="Properties\Resources.Designer.cs" />
6867
<Compile Include="SymbolNode.cs" />
69-
<Compile Include="System.Diagnostics.CodeAnalysis\**\*.cs" />
68+
<Compile Include="..\Common\Compat\**\*.cs" Link="Compat\%(RecursiveDir)%(Filename).%(Extension)" />
7069
</ItemGroup>
7170

7271
<ItemGroup>

src/System.Diagnostics.CodeAnalysis.cs

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)