Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MemberNotNull/When attributes #33567

Merged
merged 8 commits into from
Mar 19, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,41 @@ sealed class DoesNotReturnIfAttribute : Attribute
/// <summary>Gets the condition parameter value.</summary>
public bool ParameterValue { get; }
}

/// <summary>Sepcifies that the method or property will ensure that the listed field and property members have not-null values.</summary>
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AllowMultiple = false is the default and so doesn't need to be specified. Same below.

[CLSCompliant(false)]
#if INTERNAL_NULLABLE_ATTRIBUTES
internal
#else
public
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
#endif
sealed class MemberNotNullAttribute : Attribute
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>Initializes the attribute with the list of field and property members.</summary>
/// <param name="members">
/// The list of field and property members that are promised to be not-null.
/// </param>
public MemberNotNullAttribute(params string[] members) { }
}

/// <summary>Sepcifies 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>
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
[CLSCompliant(false)]
#if INTERNAL_NULLABLE_ATTRIBUTES
internal
#else
public
#endif
sealed class MemberNotNullWhenAttribute : Attribute
{
/// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary>
/// <param name="returnValue">
/// The return value condition. If the method returns this value, the associated parameter will not be null.
/// </param>
/// <param name="members">
/// The list of field and property members that are promised to be not-null.
/// </param>
public MemberNotNullWhenAttribute(bool returnValue, params string[] members) { }
}
}