-
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some nullable attributes for net4x compatibility
Part of a fix for issue #1067
- Loading branch information
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// | ||
// NullableAttributes.cs | ||
// | ||
// Author: Jeffrey Stedfast <[email protected]> | ||
// | ||
// Copyright (c) 2013-2024 .NET Foundation and Contributors | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
namespace System.Diagnostics.CodeAnalysis { | ||
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] | ||
sealed class AllowNullAttribute : Attribute | ||
{ | ||
public AllowNullAttribute () { } | ||
} | ||
|
||
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] | ||
sealed class DisallowNullAttribute : Attribute | ||
{ | ||
public DisallowNullAttribute () { } | ||
} | ||
|
||
[AttributeUsage (AttributeTargets.Parameter, Inherited = false)] | ||
sealed class DoesNotReturnAttribute : Attribute | ||
{ | ||
public DoesNotReturnAttribute () { } | ||
} | ||
|
||
[AttributeUsage (AttributeTargets.Parameter, Inherited = false)] | ||
sealed class DoesNotReturnIfAttribute : Attribute | ||
{ | ||
public DoesNotReturnIfAttribute (bool parameterValue) => ParameterValue = parameterValue; | ||
|
||
public bool ParameterValue { get; } | ||
} | ||
|
||
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] | ||
sealed class MaybeNullAttribute : Attribute | ||
{ | ||
public MaybeNullAttribute () { } | ||
} | ||
|
||
[AttributeUsage (AttributeTargets.Parameter, Inherited = false)] | ||
sealed class MaybeNullWhenAttribute : Attribute | ||
{ | ||
public MaybeNullWhenAttribute (bool returnValue) => ReturnValue = returnValue; | ||
|
||
public bool ReturnValue { get; } | ||
} | ||
|
||
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] | ||
sealed class MemberNotNullAttribute : Attribute | ||
{ | ||
public MemberNotNullAttribute (string member) => Members = new string[] { member }; | ||
|
||
public MemberNotNullAttribute (params string[] members) => Members = members; | ||
|
||
public string[] Members { get; } | ||
} | ||
|
||
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] | ||
sealed class MemberNotNullWhenAttribute : Attribute | ||
{ | ||
public MemberNotNullWhenAttribute (bool returnValue, string member) | ||
{ | ||
Members = new string[] { member }; | ||
ReturnValue = returnValue; | ||
} | ||
|
||
public MemberNotNullWhenAttribute (bool returnValue, string[] members) | ||
{ | ||
Members = members; | ||
ReturnValue = returnValue; | ||
} | ||
|
||
public string[] Members { get; } | ||
|
||
public bool ReturnValue { get; } | ||
} | ||
|
||
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] | ||
sealed class NotNullAttribute : Attribute | ||
{ | ||
public NotNullAttribute () { } | ||
} | ||
|
||
[AttributeUsage (AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] | ||
sealed class NotNullIfNotNullAttribute : Attribute | ||
{ | ||
public NotNullIfNotNullAttribute (string parameterName) => ParameterName = parameterName; | ||
|
||
public string ParameterName { get; } | ||
} | ||
|
||
[AttributeUsage (AttributeTargets.Parameter, Inherited = false)] | ||
sealed class NotNullWhenAttribute : Attribute | ||
{ | ||
public NotNullWhenAttribute (bool returnValue) => ReturnValue = returnValue; | ||
|
||
public bool ReturnValue { get; } | ||
} | ||
} |