C#C
C#2y ago
stigzler

✅ Shorten Property code

Is there a simpler way to write this:
private bool _gistEdited = false;
public bool GistEdited
{
    get {
        return _gistEdited;
    }
    set
    {
        _gistEdited = value;
        mainWindowControl.SaveButton.BorderBrush = new SolidColorBrush(Color.FromArgb(255,255,0,0));
    }
}

I know you can do:
// No private backing memeber
public int GistEdited { get; set; }

And also:
// No private backing memeber
public bool GistEdited { get => GistEdited; set => mainWindowControl.SaveButton.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)); }

But with the former, you can't do the mainWindowControl.SaveButton.BorderBrush =... and with the latter, you can't set GistEdited (as it'd result in an infinite loop)
Was this page helpful?