1+ /*==============================================================================================================================
2+ | Author Ignia, LLC
3+ | Client Ignia, LLC
4+ | Project Topics Library
5+ \=============================================================================================================================*/
6+ namespace System . Diagnostics . CodeAnalysis {
7+
8+ /*============================================================================================================================
9+ | CLASS: MEMBER NOT NULL (ATTRIBUTE)
10+ \---------------------------------------------------------------------------------------------------------------------------*/
11+ /// <summary>
12+ /// Specifies that the method or property will ensure that the listed field and property members have not-null values when
13+ /// returning with the specified return value condition.
14+ /// </summary>
15+ [ AttributeUsage ( AttributeTargets . Method | AttributeTargets . Property , Inherited = false , AllowMultiple = true ) ]
16+ internal sealed class MemberNotNullWhenAttribute : Attribute {
17+
18+ /*==========================================================================================================================
19+ | CONSTRUCTOR
20+ \-------------------------------------------------------------------------------------------------------------------------*/
21+ /// <summary>Initializes the attribute with the specified return value condition and a field or property member.</summary>
22+ /// <param name="returnValue">
23+ /// The return value condition. If the method returns this value, the associated parameter will not be null.
24+ /// </param>
25+ /// <param name="member">
26+ /// The field or property member that is promised to be not-null.
27+ /// </param>
28+ #pragma warning disable CA1019 // Define accessors for attribute arguments
29+ public MemberNotNullWhenAttribute ( bool returnValue , string member ) {
30+ ReturnValue = returnValue ;
31+ Members = new [ ] { member } ;
32+ }
33+ #pragma warning restore CA1019 // Define accessors for attribute arguments
34+
35+ /// <summary>
36+ /// Initializes the attribute with the specified return value condition and list of field and property members.
37+ /// </summary>
38+ /// <param name="returnValue">
39+ /// The return value condition. If the method returns this value, the associated parameter will not be null.
40+ /// </param>
41+ /// <param name="members">
42+ /// The list of field and property members that are promised to be not-null.
43+ /// </param>
44+ public MemberNotNullWhenAttribute ( bool returnValue , params string [ ] members ) {
45+ ReturnValue = returnValue ;
46+ Members = members ;
47+ }
48+
49+ /*==========================================================================================================================
50+ | PROPERTY: RETURN VALUE
51+ \-------------------------------------------------------------------------------------------------------------------------*/
52+ /// <summary>Gets the return value condition.</summary>
53+ public bool ReturnValue { get ; }
54+
55+ /*==========================================================================================================================
56+ | PROPERTY: MEMBERS
57+ \-------------------------------------------------------------------------------------------------------------------------*/
58+ /// <summary>Gets field or property member names.</summary>
59+ public string [ ] Members { get ; }
60+
61+ }
62+ }
0 commit comments