@@ -130,4 +130,71 @@ sealed class DoesNotReturnIfAttribute : Attribute
130130 /// <summary>Gets the condition parameter value.</summary>
131131 public bool ParameterValue { get ; }
132132 }
133+
134+ /// <summary>Specifies that the method or property will ensure that the listed field and property members have not-null values.</summary>
135+ [ AttributeUsage ( AttributeTargets . Method | AttributeTargets . Property , Inherited = false , AllowMultiple = true ) ]
136+ #if INTERNAL_NULLABLE_ATTRIBUTES
137+ internal
138+ #else
139+ public
140+ #endif
141+ sealed class MemberNotNullAttribute : Attribute
142+ {
143+ /// <summary>Initializes the attribute with a field or property member.</summary>
144+ /// <param name="member">
145+ /// The field or property member that is promised to be not-null.
146+ /// </param>
147+ public MemberNotNullAttribute ( string member ) => Members = new [ ] { member } ;
148+
149+ /// <summary>Initializes the attribute with the list of field and property members.</summary>
150+ /// <param name="members">
151+ /// The list of field and property members that are promised to be not-null.
152+ /// </param>
153+ public MemberNotNullAttribute ( params string [ ] members ) => Members = members ;
154+
155+ /// <summary>Gets field or property member names.</summary>
156+ public string [ ] Members { get ; }
157+ }
158+
159+ /// <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>
160+ [ AttributeUsage ( AttributeTargets . Method | AttributeTargets . Property , Inherited = false , AllowMultiple = true ) ]
161+ #if INTERNAL_NULLABLE_ATTRIBUTES
162+ internal
163+ #else
164+ public
165+ #endif
166+ sealed class MemberNotNullWhenAttribute : Attribute
167+ {
168+ /// <summary>Initializes the attribute with the specified return value condition and a field or property member.</summary>
169+ /// <param name="returnValue">
170+ /// The return value condition. If the method returns this value, the associated parameter will not be null.
171+ /// </param>
172+ /// <param name="member">
173+ /// The field or property member that is promised to be not-null.
174+ /// </param>
175+ public MemberNotNullWhenAttribute ( bool returnValue , string member )
176+ {
177+ ReturnValue = returnValue ;
178+ Members = new [ ] { member } ;
179+ }
180+
181+ /// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary>
182+ /// <param name="returnValue">
183+ /// The return value condition. If the method returns this value, the associated parameter will not be null.
184+ /// </param>
185+ /// <param name="members">
186+ /// The list of field and property members that are promised to be not-null.
187+ /// </param>
188+ public MemberNotNullWhenAttribute ( bool returnValue , params string [ ] members )
189+ {
190+ ReturnValue = returnValue ;
191+ Members = members ;
192+ }
193+
194+ /// <summary>Gets the return value condition.</summary>
195+ public bool ReturnValue { get ; }
196+
197+ /// <summary>Gets field or property member names.</summary>
198+ public string [ ] Members { get ; }
199+ }
133200}
0 commit comments