Skip to content

CodeAnalysis MaybeNull/AllowNull on Collections #539

Closed Answered by mganss
meixger asked this question in Q&A
Discussion options

You must be logged in to vote

I'm thinking to change the cited code like this:

private bool IsNullable => DefaultValue == null && !IsRequired;
private bool IsValueType => PropertyType is EnumModel || (PropertyType is SimpleModel model && model.ValueType.IsValueType);
private bool IsNullableValueType => IsNullable && !IsEnumerable && IsValueType;
private bool IsNullableReferenceType => IsNullable && (!IsEnumerable || !IsPrivateSetter) && (PropertyType is ClassModel || (PropertyType is SimpleModel model && !model.ValueType.IsValueType));

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@meixger
Comment options

Answer selected by meixger
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants