Skip to content

Commit 7a021a9

Browse files
authored
Remove attributes that aren't yet available in C# 8 (#1218)
* Remove attributes The `MemberNotNull` and `MemberNotNullWhen` attributes weren't available in C# 8. They were added in C# 9. * fix build warnings Missed two notes on these attributes
1 parent 2f5f317 commit 7a021a9

File tree

2 files changed

+0
-59
lines changed

2 files changed

+0
-59
lines changed

standard/attributes.md

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,6 @@ The code-analysis attributes are declared in namespace `System.Diagnostics.CodeA
877877
`MaybeNullWhen` ([§22.5.7.7](attributes.md#22577-the-maybenullwhen-attribute)) | A non-nullable argument may be null when the method returns the specified `bool` value.
878878
`NotNullWhen` ([§22.5.7.12](attributes.md#225712-the-notnullwhen-attribute)) | A nullable argument won’t be null when the method returns the specified `bool` value.
879879
`NotNullIfNotNull` ([§22.5.7.11](attributes.md#225711-the-notnullifnotnull-attribute)) | A return value isn’t null if the argument for the specified parameter isn’t null.
880-
`MemberNotNull` ([§22.5.7.8](attributes.md#22578-the-membernotnull-attribute)) | The listed member won’t be null when the method returns.
881-
`MemberNotNullWhen` ([§22.5.7.9](attributes.md#22579-the-membernotnullwhen-attribute)) | The listed member won’t be null when the method returns the specified `bool` value.
882880
`DoesNotReturn` ([§22.5.7.4](attributes.md#22574-the-doesnotreturn-attribute)) | This method never returns.
883881
`DoesNotReturnIf` ([§22.5.7.5](attributes.md#22575-the-doesnotreturnif-attribute)) | This method never returns if the associated `bool` parameter has the specified value.
884882
@@ -1032,47 +1030,6 @@ Specifies that a non-nullable return value may be null.
10321030
10331031
Specifies that a non-nullable argument may be `null` when the method returns the specified `bool` value. This is similar to the `MaybeNull` attribute ([§22.5.7.6](attributes.md#22576-the-maybenull-attribute)), but includes a parameter for the specified return value.
10341032
1035-
#### 22.5.7.8 The MemberNotNull attribute
1036-
1037-
Specifies that the given member wont be `null` when the method returns.
1038-
1039-
> *Example*: A helper method may include the `MemberNotNull` attribute to list any fields that are assigned to a non-null value in that method. A compiler that analyzes constructors to determine whether all non-nullable reference fields have been initialized may then use this attribute to discover which fields have been set by those helper methods. Consider the following example:
1040-
>
1041-
> <!-- Example: {template:"standalone-lib", name:"MemberNotNullAttribute"} -->
1042-
> ```csharp
1043-
> #nullable enable
1044-
> public class Container
1045-
> {
1046-
> private string _uniqueIdentifier; // must be initialized.
1047-
> private string? _optionalMessage;
1048-
>
1049-
> public Container()
1050-
> {
1051-
> Helper();
1052-
> }
1053-
>
1054-
> public Container(string message)
1055-
> {
1056-
> Helper();
1057-
> _optionalMessage = message;
1058-
> }
1059-
>
1060-
> [MemberNotNull(nameof(_uniqueIdentifier))]
1061-
> private void Helper()
1062-
> {
1063-
> _uniqueIdentifier = DateTime.Now.Ticks.ToString();
1064-
> }
1065-
> }
1066-
> ```
1067-
>
1068-
> Multiple field names may be given as arguments to the attributes constructor. *end example*
1069-
1070-
#### 22.5.7.9 The MemberNotNullWhen attribute
1071-
1072-
Specifies that the listed member wont be `null` when the method returns the specified `bool` value.
1073-
1074-
> *Example*: This attribute is like `MemberNotNull` ([§22.5.7.8](attributes.md#22578-the-membernotnull-attribute)) except that `MemberNotNullWhen` takes a `bool` argument. `MemberNotNullWhen` is intended for use in situations in which a helper method returns a `bool` indicating whether it initialized fields. *end example*
1075-
10761033
#### 22.5.7.10 The NotNull attribute
10771034
10781035
Specifies that a nullable value will never be `null` if the method returns (rather than throwing).

standard/standard-library.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -614,22 +614,6 @@ namespace System.Runtime.CompilerServices
614614
public MaybeNullWhenAttribute(bool returnValue) {}
615615
}
616616

617-
[System.AttributeUsage(System.AttributeTargets.Method |
618-
System.AttributeTargets.Property, AllowMultiple=true, Inherited=false)]
619-
public sealed class MemberNotNullAttribute : Attribute
620-
{
621-
public MemberNotNullAttribute(string member) {}
622-
public MemberNotNullAttribute(params string[] members) {}
623-
}
624-
625-
[System.AttributeUsage(System.AttributeTargets.Method |
626-
System.AttributeTargets.Property, AllowMultiple=true, Inherited=false)]
627-
public sealed class MemberNotNullWhenAttribute : Attribute
628-
{
629-
public MemberNotNullWhenAttribute(bool returnValue, string member) {}
630-
public MemberNotNullWhenAttribute(bool returnValue, params string[] members) {}
631-
}
632-
633617
[System.AttributeUsage(System.AttributeTargets.Field |
634618
System.AttributeTargets.Parameter | System.AttributeTargets.Property |
635619
System.AttributeTargets.ReturnValue, Inherited=false)]

0 commit comments

Comments
 (0)