c# сообщить компилятору, что свойство не null после вызова метода

Как сообщить анализатору Visual Studio, что свойство свойства не null, после вызова внутреннего метода?

Inner class:

class Inner
{
    int? Property { get; set; }

    [MemberNotNull(nameof(Property))]
    void Initialize
    {
        Property = 42;
    }
}

Caller class:

class Caller
{
    // We know here that constructor is always called before other methods
    public Caller()
    {
        InnerObj = new Inner();

        // We know here that InnerObj.Property is always not null
        InnerObj.Initialize();
    }

    public Inner InnerObj { get; }

    public void MethodWithNullWarning()
    {
        // Null Warning
        InnerObj.Property.ToString();
    }
}

Ответы (0 шт):