|
| 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 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +namespace System.Diagnostics.CodeAnalysis |
| 6 | +{ |
| 7 | +#if NETSTANDARD2_0 |
| 8 | + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)] |
| 9 | + internal sealed class AllowNullAttribute : Attribute |
| 10 | + { |
| 11 | + } |
| 12 | + |
| 13 | + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)] |
| 14 | + internal sealed class DisallowNullAttribute : Attribute |
| 15 | + { |
| 16 | + } |
| 17 | + |
| 18 | + [AttributeUsage(AttributeTargets.Method)] |
| 19 | + internal sealed class DoesNotReturnAttribute : Attribute |
| 20 | + { |
| 21 | + } |
| 22 | + |
| 23 | + [AttributeUsage(AttributeTargets.Parameter)] |
| 24 | + internal sealed class DoesNotReturnIfAttribute : Attribute |
| 25 | + { |
| 26 | + public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; |
| 27 | + public bool ParameterValue { get; } |
| 28 | + } |
| 29 | + |
| 30 | + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)] |
| 31 | + internal sealed class MaybeNullAttribute : Attribute |
| 32 | + { |
| 33 | + } |
| 34 | + |
| 35 | + [AttributeUsage(AttributeTargets.Parameter)] |
| 36 | + internal sealed class MaybeNullWhenAttribute : Attribute |
| 37 | + { |
| 38 | + public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; |
| 39 | + public bool ReturnValue { get; } |
| 40 | + } |
| 41 | + |
| 42 | + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)] |
| 43 | + internal sealed class NotNullAttribute : Attribute |
| 44 | + { |
| 45 | + } |
| 46 | + |
| 47 | + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true)] |
| 48 | + internal sealed class NotNullIfNotNullAttribute : Attribute |
| 49 | + { |
| 50 | + public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; |
| 51 | + public string ParameterName { get; } |
| 52 | + } |
| 53 | + |
| 54 | + [AttributeUsage(AttributeTargets.Parameter)] |
| 55 | + internal sealed class NotNullWhenAttribute : Attribute |
| 56 | + { |
| 57 | + public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; |
| 58 | + public bool ReturnValue { get; } |
| 59 | + } |
| 60 | +#endif |
| 61 | + |
| 62 | +#if !NET5_0_OR_GREATER |
| 63 | + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true, Inherited = false)] |
| 64 | + internal sealed class MemberNotNullAttribute : Attribute |
| 65 | + { |
| 66 | + public MemberNotNullAttribute(string member) => Members = new string[] |
| 67 | + { |
| 68 | + member |
| 69 | + }; |
| 70 | + |
| 71 | + public MemberNotNullAttribute(params string[] members) => Members = members; |
| 72 | + |
| 73 | + public string[] Members { get; } |
| 74 | + } |
| 75 | + |
| 76 | + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true, Inherited = false)] |
| 77 | + internal sealed class MemberNotNullWhenAttribute : Attribute |
| 78 | + { |
| 79 | + public MemberNotNullWhenAttribute(bool returnValue, string member) |
| 80 | + { |
| 81 | + ReturnValue = returnValue; |
| 82 | + Members = new string[1] { member }; |
| 83 | + } |
| 84 | + |
| 85 | + public MemberNotNullWhenAttribute(bool returnValue, params string[] members) |
| 86 | + { |
| 87 | + ReturnValue = returnValue; |
| 88 | + Members = members; |
| 89 | + } |
| 90 | + |
| 91 | + public bool ReturnValue { get; } |
| 92 | + |
| 93 | + public string[] Members { get; } |
| 94 | + } |
| 95 | +#endif |
| 96 | +} |
0 commit comments