Skip to content

Hiding fails when there is a nullability difference. #4213

Answered by canton7
sjb-sjb asked this question in Q&A
Discussion options

You must be logged in to vote

Note that your PropertyName doesn't have an access modifier, which makes it private.

If you make it public, then the nullability seems to work fine. This doesn't throw a warning:

public class C
{
    public void M(NonemptyPropertyChangedEventArgs e)
    {
        Console.WriteLine(e.PropertyName.Length);
    }
}

public class NonemptyPropertyChangedEventArgs : PropertyChangedEventArgs
{
    public NonemptyPropertyChangedEventArgs(string propertyName) : base(propertyName) 
    {
    }
    public new string PropertyName => base.PropertyName ?? throw new Exception();
}

Dotnetfiddle (I'm not using SharpLab, as it doesn't seem to be referencing .NET 5, which is where PropertyChangedEventArgs i…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@sjb-sjb
Comment options

@CyrusNajmabadi
Comment options

Comment options

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

Answer selected by 333fred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants