MemberNotNullWhen on interface members? #8682
Answered
by
HaloFour
weitzhandler
asked this question in
General
-
Hi, I'm trying to apply public interface IPathSegment
{
public int? DescriptorId { get; }
[MemberNotNullWhen(true, nameof(DescriptorId))]
public bool IsFinal => ...
} But when I do the following I still get an error when accessing var segment = GetPathSegment();
if (segment.IsFinal)
{
int descriptorId = segment.DescriptorId; // error - cannot implicitly convert int? to int
} Is there a way to use these diagnostic attributes with interfaces? |
Beta Was this translation helpful? Give feedback.
Answered by
HaloFour
Nov 24, 2024
Replies: 1 comment 2 replies
-
Those attributes apply to nullable reference types, not value types. You still have to cast from |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
weitzhandler
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Those attributes apply to nullable reference types, not value types. You still have to cast from
int?
toint
as they are two separate types.