Monday, 8 September 2014

Interesting code formatting.

While investigating something completely unrelated I came across this interesting formatting option for C# properties that rely on backing fields. Here it is.

public ICommand PreviewDropCommand
{
    get { return _PreviewDropCommand ?? (_PreviewDropCommand = new RelayCommand(HandlePreviewDrop)); }
    set
    {
        _PreviewDropCommand = value;
        NotifyPropertyChanged("PreviewDropCommand");
    }
} private ICommand _PreviewDropCommand;

This looks very nice and keeps the definition of the backing field tied closely to the property getter/setter implementation.