Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernized accessor syntax in several places #13044

Merged
merged 5 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,10 @@ private class StyledPropertyClass : AvaloniaObject

public double DoubleValue
{
get { return GetValue(DoubleValueProperty); }
set { SetValue(DoubleValueProperty, value); }
get => GetValue(DoubleValueProperty);
set => SetValue(DoubleValueProperty, value);
}

public static StyledProperty<double?> NullableDoubleProperty =
AvaloniaProperty.Register<StyledPropertyClass, double?>(nameof(NullableDoubleProperty), -1);

Expand All @@ -724,8 +724,8 @@ private class DirectPropertyClass : AvaloniaObject
private double _doubleValue;
public double DoubleValue
{
get { return _doubleValue; }
set { SetAndRaise(DoubleValueProperty, ref _doubleValue, value); }
get => _doubleValue;
set => SetAndRaise(DoubleValueProperty, ref _doubleValue, value);
}
}

Expand Down Expand Up @@ -756,7 +756,7 @@ private class TestStackOverflowViewModel : INotifyPropertyChanged

public double Value
{
get { return _value; }
get => _value;
set
{
if (_value != value)
Expand All @@ -765,8 +765,10 @@ public double Value
if (SetterInvokedCount < MaxInvokedCount)
{
_value = (int)value;
if (_value > 75) _value = 75;
if (_value < 25) _value = 25;
if (_value > 75)
_value = 75;
if (_value < 25)
_value = 25;
}
else
{
Expand All @@ -788,8 +790,8 @@ private class TwoWayBindingTest : Control

public string TwoWay
{
get { return GetValue(TwoWayProperty); }
set { SetValue(TwoWayProperty, value); }
get => GetValue(TwoWayProperty);
set => SetValue(TwoWayProperty, value);
}
}

Expand All @@ -800,7 +802,7 @@ public class Source : INotifyPropertyChanged

public string Foo
{
get { return _foo; }
get => _foo;
set
{
_foo = value;
Expand Down Expand Up @@ -911,8 +913,8 @@ private class InheritanceTest : Decorator

public int Baz
{
get { return GetValue(BazProperty); }
set { SetValue(BazProperty, value); }
get => GetValue(BazProperty);
set => SetValue(BazProperty, value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Source : INotifyPropertyChanged

public string Foo
{
get { return _foo; }
get => _foo;
set
{
_foo = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ private class Class1 : AvaloniaObject

public Class1 Next
{
get { return GetValue(NextProperty); }
set { SetValue(NextProperty, value); }
get => GetValue(NextProperty);
set => SetValue(NextProperty, value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ private class NonIntegerIndexer : NotifyingBase

public string this[string key]
{
get
{
return _storage[key];
}
get => _storage[key];
set
{
_storage[key] = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ private class Class1 : StyledElement
public static readonly StyledProperty<string> FooProperty =
AvaloniaProperty.Register<Class1, string>("Foo");

public ThemeVariant ThemeVariant
{
get { throw new NotImplementedException(); }
}
public ThemeVariant ThemeVariant => throw new NotImplementedException();

public event EventHandler ThemeVariantChanged;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,7 @@ private class ViewModel : INotifyPropertyChanged
object _parameter;
public object Parameter
{
get
{
return _parameter;
}
get => _parameter;
set
{
if (_parameter == value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1949,10 +1949,7 @@ public class NonIntegerIndexer : NotifyingBase, INonIntegerIndexerDerived

public string this[string key]
{
get
{
return _storage[key];
}
get => _storage[key];
set
{
_storage[key] = value;
Expand Down Expand Up @@ -1991,10 +1988,7 @@ public class MethodAsCommandDataContext : INotifyPropertyChanged
object _parameter;
public object Parameter
{
get
{
return _parameter;
}
get => _parameter;
set
{
if (_parameter == value)
Expand Down Expand Up @@ -2050,8 +2044,8 @@ public class DataGridLikeControl : Control
private IEnumerable _items;
public IEnumerable Items
{
get { return _items; }
set { SetAndRaise(ItemsProperty, ref _items, value); }
get => _items;
set => SetAndRaise(ItemsProperty, ref _items, value);
}

public AvaloniaList<DataGridLikeColumn> Columns { get; } = new();
Expand Down
10 changes: 5 additions & 5 deletions tests/Avalonia.Markup.Xaml.UnitTests/SampleAvaloniaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ internal class SampleAvaloniaObject : AvaloniaObject

public int Int
{
get { return GetValue(IntProperty); }
set { SetValue(IntProperty, value); }
get => GetValue(IntProperty);
set => SetValue(IntProperty, value);
}

public string String
{
get { return GetValue(StringProperty); }
set { SetValue(StringProperty, value); }
get => GetValue(StringProperty);
set => SetValue(StringProperty, value);
}
}
}
}
6 changes: 3 additions & 3 deletions tests/Avalonia.Markup.Xaml.UnitTests/TestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TestViewModel : NotifyingBase

public int Integer
{
get { return _integer; }
get => _integer;
set
{
_integer = value;
Expand All @@ -20,7 +20,7 @@ public int Integer

public string String
{
get { return _string; }
get => _string;
set
{
_string = value;
Expand All @@ -30,7 +30,7 @@ public string String

public TestViewModel Child
{
get { return _child; }
get => _child;
set
{
_child = value;
Expand Down
2 changes: 1 addition & 1 deletion tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ private class SelectedItemsViewModel : INotifyPropertyChanged

public IList SelectedItems
{
get { return _selectedItems; }
get => _selectedItems;
set
{
_selectedItems = value;
Expand Down
13 changes: 5 additions & 8 deletions tests/Avalonia.Markup.Xaml.UnitTests/Xaml/NonControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@ public class NonControl : AvaloniaObject

public Control Control
{
get { return GetValue(ControlProperty); }
set { SetValue(ControlProperty, value); }
get => GetValue(ControlProperty);
set => SetValue(ControlProperty, value);
}

public string String
{
get { return GetValue(StringProperty); }
set { SetValue(StringProperty, value); }
get => GetValue(StringProperty);
set => SetValue(StringProperty, value);
}

public string Bar
{
get { return GetValue(BarProperty); }
}
public string Bar => GetValue(BarProperty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ private class Class1 : AvaloniaObject

public string Foo
{
get { return GetValue(FooProperty); }
set { SetValue(FooProperty, value); }
get => GetValue(FooProperty);
set => SetValue(FooProperty, value);
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions tests/Avalonia.RenderTests/Media/ImageBrushTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ public ImageBrushTests()
{
}

private string BitmapPath
{
get { return System.IO.Path.Combine(OutputPath, "github_icon.png"); }
}
private string BitmapPath => System.IO.Path.Combine(OutputPath, "github_icon.png");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is a step too far. It's less easy to read. The below would have been enough. Yes, this is dev preference which is why I would change less actually. Other people will have different opinions I'm sure.

        private string BitmapPath
        {
            get => System.IO.Path.Combine(OutputPath, "github_icon.png");
        }


private string SmallBitmapPath
{
get { return System.IO.Path.Combine(OutputPath, "github_icon_small.png"); }
}
private string SmallBitmapPath => System.IO.Path.Combine(OutputPath, "github_icon_small.png");

[Fact]
public async Task ImageBrush_NullSource()
Expand Down
5 changes: 1 addition & 4 deletions tests/Avalonia.RenderTests/Media/ImageDrawingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public ImageDrawingTests()
{
}

private string BitmapPath
{
get { return System.IO.Path.Combine(OutputPath, "github_icon.png"); }
}
private string BitmapPath => System.IO.Path.Combine(OutputPath, "github_icon.png");

[Fact]
public async Task ImageDrawing_Fill()
Expand Down
17 changes: 4 additions & 13 deletions tests/Avalonia.RenderTests/Media/VisualBrushTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@ public VisualBrushTests()
{
}

private string BitmapPath
{
get { return System.IO.Path.Combine(OutputPath, "github_icon.png"); }
}
private string BitmapPath => System.IO.Path.Combine(OutputPath, "github_icon.png");

private Control Visual
private Control Visual => new Panel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a code block in a getter you really shouldn't be "modernizing" it IMO. It is entirely developer preference in that case.

{
get
{
return new Panel
{
Children =
Children =
{
new Image
{
Expand All @@ -50,9 +43,7 @@ private Control Visual
}
}
}
};
}
}
};

[Fact]
public async Task VisualBrush_NoStretch_NoTile_Alignment_TopLeft()
Expand Down