浏览代码

Modernized accessor syntax in several places (#13044)

* Modernized accessor syntax in several places

* Toned down the getter modernization

* Block body for properties with code

---------

Co-authored-by: Lehonti Ramos <lehonti@ramos>
Lehonti Ramos 2 年之前
父节点
当前提交
d1444b4f7c

+ 11 - 11
tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs

@@ -699,10 +699,10 @@ namespace Avalonia.Markup.UnitTests.Data
 
             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);
 
@@ -724,8 +724,8 @@ namespace Avalonia.Markup.UnitTests.Data
             private double _doubleValue;
             public double DoubleValue
             {
-                get { return _doubleValue; }
-                set { SetAndRaise(DoubleValueProperty, ref _doubleValue, value); }
+                get => _doubleValue;
+                set => SetAndRaise(DoubleValueProperty, ref _doubleValue, value);
             }
         }
 
@@ -756,7 +756,7 @@ namespace Avalonia.Markup.UnitTests.Data
 
             public double Value
             {
-                get { return _value; }
+                get => _value;
                 set
                 {
                     if (_value != value)
@@ -788,8 +788,8 @@ namespace Avalonia.Markup.UnitTests.Data
 
             public string TwoWay
             {
-                get { return GetValue(TwoWayProperty); }
-                set { SetValue(TwoWayProperty, value); }
+                get => GetValue(TwoWayProperty);
+                set => SetValue(TwoWayProperty, value);
             }
         }
 
@@ -800,7 +800,7 @@ namespace Avalonia.Markup.UnitTests.Data
 
             public string Foo
             {
-                get { return _foo; }
+                get => _foo;
                 set
                 {
                     _foo = value;
@@ -911,8 +911,8 @@ namespace Avalonia.Markup.UnitTests.Data
 
             public int Baz
             {
-                get { return GetValue(BazProperty); }
-                set { SetValue(BazProperty, value); }
+                get => GetValue(BazProperty);
+                set => SetValue(BazProperty, value);
             }
         }
     }

+ 1 - 1
tests/Avalonia.Markup.UnitTests/Data/BindingTests_Source.cs

@@ -28,7 +28,7 @@ namespace Avalonia.Markup.UnitTests.Data
 
             public string Foo
             {
-                get { return _foo; }
+                get => _foo;
                 set
                 {
                     _foo = value;

+ 2 - 2
tests/Avalonia.Markup.UnitTests/Parsers/ExpressionObserverBuilderTests_AttachedProperty.cs

@@ -158,8 +158,8 @@ namespace Avalonia.Markup.UnitTests.Parsers
 
             public Class1 Next
             {
-                get { return GetValue(NextProperty); }
-                set { SetValue(NextProperty, value); }
+                get => GetValue(NextProperty);
+                set => SetValue(NextProperty, value);
             }
         }
     }

+ 1 - 4
tests/Avalonia.Markup.UnitTests/Parsers/ExpressionObserverBuilderTests_Indexer.cs

@@ -369,10 +369,7 @@ namespace Avalonia.Markup.UnitTests.Parsers
 
             public string this[string key]
             {
-                get
-                {
-                    return _storage[key];
-                }
+                get => _storage[key];
                 set
                 {
                     _storage[key] = value;

+ 2 - 2
tests/Avalonia.Markup.Xaml.UnitTests/Converters/AvaloniaPropertyConverterTest.cs

@@ -115,9 +115,9 @@ namespace Avalonia.Markup.Xaml.UnitTests.Converters
             public static readonly StyledProperty<string> FooProperty =
                 AvaloniaProperty.Register<Class1, string>("Foo");
 
-            public ThemeVariant ThemeVariant 
+            public ThemeVariant ThemeVariant
             {
-                get { throw new NotImplementedException(); }
+                get => throw new NotImplementedException();
             }
 
             public event EventHandler ThemeVariantChanged;

+ 1 - 4
tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_Method.cs

@@ -231,10 +231,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Data
             object _parameter;
             public object Parameter
             {
-                get
-                {
-                    return _parameter;
-                }
+                get => _parameter;
                 set
                 {
                     if (_parameter == value)

+ 4 - 10
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs

@@ -1949,10 +1949,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
 
             public string this[string key]
             {
-                get
-                {
-                    return _storage[key];
-                }
+                get => _storage[key];
                 set
                 {
                     _storage[key] = value;
@@ -1991,10 +1988,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
         object _parameter;
         public object Parameter
         {
-            get
-            {
-                return _parameter;
-            }
+            get => _parameter;
             set
             {
                 if (_parameter == value)
@@ -2050,8 +2044,8 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
         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();

+ 5 - 5
tests/Avalonia.Markup.Xaml.UnitTests/SampleAvaloniaObject.cs

@@ -12,14 +12,14 @@ namespace Avalonia.Markup.Xaml.UnitTests
 
         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);
         }
     }
-}
+}

+ 3 - 3
tests/Avalonia.Markup.Xaml.UnitTests/TestViewModel.cs

@@ -10,7 +10,7 @@ namespace Avalonia.Markup.Xaml.UnitTests
 
         public int Integer
         {
-            get { return _integer; }
+            get => _integer;
             set
             {
                 _integer = value;
@@ -20,7 +20,7 @@ namespace Avalonia.Markup.Xaml.UnitTests
 
         public string String
         {
-            get { return _string; }
+            get => _string;
             set
             {
                 _string = value;
@@ -30,7 +30,7 @@ namespace Avalonia.Markup.Xaml.UnitTests
 
         public TestViewModel Child
         {
-            get { return _child; }
+            get => _child;
             set
             {
                 _child = value;

+ 1 - 1
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs

@@ -990,7 +990,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
 
             public IList SelectedItems
             {
-                get { return _selectedItems; }
+                get => _selectedItems;
                 set
                 {
                     _selectedItems = value;

+ 5 - 8
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/NonControl.cs

@@ -20,19 +20,16 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
 
         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);
     }
 }

+ 2 - 2
tests/Avalonia.ReactiveUI.UnitTests/AvaloniaObjectTests_GetSubject.cs

@@ -37,8 +37,8 @@ namespace Avalonia.ReactiveUI.UnitTests
 
             public string Foo
             {
-                get { return GetValue(FooProperty); }
-                set { SetValue(FooProperty, value); }
+                get => GetValue(FooProperty);
+                set => SetValue(FooProperty, value);
             }
         }
     }

+ 8 - 2
tests/Avalonia.RenderTests/Media/ImageBrushTests.cs

@@ -21,12 +21,18 @@ namespace Avalonia.Direct2D1.RenderTests.Media
 
         private string BitmapPath
         {
-            get { return System.IO.Path.Combine(OutputPath, "github_icon.png"); }
+            get
+            {
+                return System.IO.Path.Combine(OutputPath, "github_icon.png");
+            }
         }
 
         private string SmallBitmapPath
         {
-            get { return System.IO.Path.Combine(OutputPath, "github_icon_small.png"); }
+            get
+            {
+                return System.IO.Path.Combine(OutputPath, "github_icon_small.png");
+            }
         }
 
         [Fact]

+ 4 - 1
tests/Avalonia.RenderTests/Media/ImageDrawingTests.cs

@@ -19,7 +19,10 @@ namespace Avalonia.Direct2D1.RenderTests.Media
 
         private string BitmapPath
         {
-            get { return System.IO.Path.Combine(OutputPath, "github_icon.png"); }
+            get
+            {
+                return System.IO.Path.Combine(OutputPath, "github_icon.png");
+            }
         }
 
         [Fact]

+ 4 - 1
tests/Avalonia.RenderTests/Media/VisualBrushTests.cs

@@ -21,7 +21,10 @@ namespace Avalonia.Direct2D1.RenderTests.Media
 
         private string BitmapPath
         {
-            get { return System.IO.Path.Combine(OutputPath, "github_icon.png"); }
+            get
+            {
+                return System.IO.Path.Combine(OutputPath, "github_icon.png");
+            }
         }
 
         private Control Visual