|  | 
|  | 1 | +#if !SYSTEM_DIAGNOSTICS_CODEANALYSIS_NULLABILITY | 
|  | 2 | + | 
|  | 3 | +// This was copied from https://github.com/dotnet/runtime/blob/39b9607807f29e48cae4652cd74735182b31182e/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs | 
|  | 4 | +// and updated to have the scope of the attributes be internal. | 
|  | 5 | +namespace System.Diagnostics.CodeAnalysis | 
|  | 6 | +{ | 
|  | 7 | + | 
|  | 8 | +    /// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary> | 
|  | 9 | +    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] | 
|  | 10 | +    internal sealed class AllowNullAttribute : Attribute { } | 
|  | 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 | +    /// <summary>Specifies that an output may be null even if the corresponding type disallows it.</summary> | 
|  | 17 | +    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] | 
|  | 18 | +    internal sealed class MaybeNullAttribute : Attribute { } | 
|  | 19 | + | 
|  | 20 | +    /// <summary>Specifies that an output will not be null even if the corresponding type allows it.</summary> | 
|  | 21 | +    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] | 
|  | 22 | +    internal sealed class NotNullAttribute : Attribute { } | 
|  | 23 | + | 
|  | 24 | +    /// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter may be null even if the corresponding type disallows it.</summary> | 
|  | 25 | +    [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] | 
|  | 26 | +    internal sealed class MaybeNullWhenAttribute : Attribute | 
|  | 27 | +    { | 
|  | 28 | +        /// <summary>Initializes the attribute with the specified return value condition.</summary> | 
|  | 29 | +        /// <param name="returnValue"> | 
|  | 30 | +        /// The return value condition. If the method returns this value, the associated parameter may be null. | 
|  | 31 | +        /// </param> | 
|  | 32 | +        public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; | 
|  | 33 | + | 
|  | 34 | +        /// <summary>Gets the return value condition.</summary> | 
|  | 35 | +        public bool ReturnValue { get; } | 
|  | 36 | +    } | 
|  | 37 | + | 
|  | 38 | +    /// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter will not be null even if the corresponding type allows it.</summary> | 
|  | 39 | +    [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] | 
|  | 40 | +    internal sealed class NotNullWhenAttribute : Attribute | 
|  | 41 | +    { | 
|  | 42 | +        /// <summary>Initializes the attribute with the specified return value condition.</summary> | 
|  | 43 | +        /// <param name="returnValue"> | 
|  | 44 | +        /// The return value condition. If the method returns this value, the associated parameter will not be null. | 
|  | 45 | +        /// </param> | 
|  | 46 | +        public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; | 
|  | 47 | + | 
|  | 48 | +        /// <summary>Gets the return value condition.</summary> | 
|  | 49 | +        public bool ReturnValue { get; } | 
|  | 50 | +    } | 
|  | 51 | + | 
|  | 52 | +    /// <summary>Specifies that the output will be non-null if the named parameter is non-null.</summary> | 
|  | 53 | +    [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] | 
|  | 54 | +    internal sealed class NotNullIfNotNullAttribute : Attribute | 
|  | 55 | +    { | 
|  | 56 | +        /// <summary>Initializes the attribute with the associated parameter name.</summary> | 
|  | 57 | +        /// <param name="parameterName"> | 
|  | 58 | +        /// The associated parameter name.  The output will be non-null if the argument to the parameter specified is non-null. | 
|  | 59 | +        /// </param> | 
|  | 60 | +        public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; | 
|  | 61 | + | 
|  | 62 | +        /// <summary>Gets the associated parameter name.</summary> | 
|  | 63 | +        public string ParameterName { get; } | 
|  | 64 | +    } | 
|  | 65 | + | 
|  | 66 | +    /// <summary>Applied to a method that will never return under any circumstance.</summary> | 
|  | 67 | +    [AttributeUsage(AttributeTargets.Method, Inherited = false)] | 
|  | 68 | +    internal sealed class DoesNotReturnAttribute : Attribute { } | 
|  | 69 | + | 
|  | 70 | +    /// <summary>Specifies that the method will not return if the associated Boolean parameter is passed the specified value.</summary> | 
|  | 71 | +    [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] | 
|  | 72 | +    internal sealed class DoesNotReturnIfAttribute : Attribute | 
|  | 73 | +    { | 
|  | 74 | +        /// <summary>Initializes the attribute with the specified parameter value.</summary> | 
|  | 75 | +        /// <param name="parameterValue"> | 
|  | 76 | +        /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to | 
|  | 77 | +        /// the associated parameter matches this value. | 
|  | 78 | +        /// </param> | 
|  | 79 | +        public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; | 
|  | 80 | + | 
|  | 81 | +        /// <summary>Gets the condition parameter value.</summary> | 
|  | 82 | +        public bool ParameterValue { get; } | 
|  | 83 | +    } | 
|  | 84 | + | 
|  | 85 | +    /// <summary>Specifies that the method or property will ensure that the listed field and property members have not-null values.</summary> | 
|  | 86 | +    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] | 
|  | 87 | +    internal sealed class MemberNotNullAttribute : Attribute | 
|  | 88 | +    { | 
|  | 89 | +        /// <summary>Initializes the attribute with a field or property member.</summary> | 
|  | 90 | +        /// <param name="member"> | 
|  | 91 | +        /// The field or property member that is promised to be not-null. | 
|  | 92 | +        /// </param> | 
|  | 93 | +        public MemberNotNullAttribute(string member) => Members = new[] { member }; | 
|  | 94 | + | 
|  | 95 | +        /// <summary>Initializes the attribute with the list of field and property members.</summary> | 
|  | 96 | +        /// <param name="members"> | 
|  | 97 | +        /// The list of field and property members that are promised to be not-null. | 
|  | 98 | +        /// </param> | 
|  | 99 | +        public MemberNotNullAttribute(params string[] members) => Members = members; | 
|  | 100 | + | 
|  | 101 | +        /// <summary>Gets field or property member names.</summary> | 
|  | 102 | +        public string[] Members { get; } | 
|  | 103 | +    } | 
|  | 104 | + | 
|  | 105 | +    /// <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> | 
|  | 106 | +    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] | 
|  | 107 | +    internal sealed class MemberNotNullWhenAttribute : Attribute | 
|  | 108 | +    { | 
|  | 109 | +        /// <summary>Initializes the attribute with the specified return value condition and a field or property member.</summary> | 
|  | 110 | +        /// <param name="returnValue"> | 
|  | 111 | +        /// The return value condition. If the method returns this value, the associated parameter will not be null. | 
|  | 112 | +        /// </param> | 
|  | 113 | +        /// <param name="member"> | 
|  | 114 | +        /// The field or property member that is promised to be not-null. | 
|  | 115 | +        /// </param> | 
|  | 116 | +        public MemberNotNullWhenAttribute(bool returnValue, string member) | 
|  | 117 | +        { | 
|  | 118 | +            ReturnValue = returnValue; | 
|  | 119 | +            Members = new[] { member }; | 
|  | 120 | +        } | 
|  | 121 | + | 
|  | 122 | +        /// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary> | 
|  | 123 | +        /// <param name="returnValue"> | 
|  | 124 | +        /// The return value condition. If the method returns this value, the associated parameter will not be null. | 
|  | 125 | +        /// </param> | 
|  | 126 | +        /// <param name="members"> | 
|  | 127 | +        /// The list of field and property members that are promised to be not-null. | 
|  | 128 | +        /// </param> | 
|  | 129 | +        public MemberNotNullWhenAttribute(bool returnValue, params string[] members) | 
|  | 130 | +        { | 
|  | 131 | +            ReturnValue = returnValue; | 
|  | 132 | +            Members = members; | 
|  | 133 | +        } | 
|  | 134 | + | 
|  | 135 | +        /// <summary>Gets the return value condition.</summary> | 
|  | 136 | +        public bool ReturnValue { get; } | 
|  | 137 | + | 
|  | 138 | +        /// <summary>Gets field or property member names.</summary> | 
|  | 139 | +        public string[] Members { get; } | 
|  | 140 | +    } | 
|  | 141 | +} | 
|  | 142 | +#endif | 
0 commit comments