From b6923f8089f85a9826927affc728535acb07c3b6 Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Sat, 16 May 2020 23:13:05 +0200 Subject: [PATCH] Enable nullable annotations for Shape. --- src/Avalonia.Controls/Shapes/Shape.cs | 37 +++++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Avalonia.Controls/Shapes/Shape.cs b/src/Avalonia.Controls/Shapes/Shape.cs index fc939d2a38..7d1525afc4 100644 --- a/src/Avalonia.Controls/Shapes/Shape.cs +++ b/src/Avalonia.Controls/Shapes/Shape.cs @@ -2,6 +2,8 @@ using System; using Avalonia.Collections; using Avalonia.Media; +#nullable enable + namespace Avalonia.Controls.Shapes { /// @@ -12,8 +14,8 @@ namespace Avalonia.Controls.Shapes /// /// Defines the property. /// - public static readonly StyledProperty FillProperty = - AvaloniaProperty.Register(nameof(Fill)); + public static readonly StyledProperty FillProperty = + AvaloniaProperty.Register(nameof(Fill)); /// /// Defines the property. @@ -24,14 +26,14 @@ namespace Avalonia.Controls.Shapes /// /// Defines the property. /// - public static readonly StyledProperty StrokeProperty = - AvaloniaProperty.Register(nameof(Stroke)); + public static readonly StyledProperty StrokeProperty = + AvaloniaProperty.Register(nameof(Stroke)); /// /// Defines the property. /// - public static readonly StyledProperty> StrokeDashArrayProperty = - AvaloniaProperty.Register>(nameof(StrokeDashArray)); + public static readonly StyledProperty?> StrokeDashArrayProperty = + AvaloniaProperty.Register?>(nameof(StrokeDashArray)); /// /// Defines the property. @@ -58,8 +60,8 @@ namespace Avalonia.Controls.Shapes AvaloniaProperty.Register(nameof(StrokeJoin), PenLineJoin.Miter); private Matrix _transform = Matrix.Identity; - private Geometry _definingGeometry; - private Geometry _renderedGeometry; + private Geometry? _definingGeometry; + private Geometry? _renderedGeometry; private bool _calculateTransformOnArrange; static Shape() @@ -73,7 +75,7 @@ namespace Avalonia.Controls.Shapes /// /// Gets a value that represents the of the shape. /// - public Geometry DefiningGeometry + public Geometry? DefiningGeometry { get { @@ -89,7 +91,7 @@ namespace Avalonia.Controls.Shapes /// /// Gets a value that represents the final rendered of the shape. /// - public Geometry RenderedGeometry + public Geometry? RenderedGeometry { get { @@ -123,7 +125,7 @@ namespace Avalonia.Controls.Shapes /// /// Gets or sets the that specifies how the shape's interior is painted. /// - public IBrush Fill + public IBrush? Fill { get { return GetValue(FillProperty); } set { SetValue(FillProperty, value); } @@ -141,7 +143,7 @@ namespace Avalonia.Controls.Shapes /// /// Gets or sets the that specifies how the shape's outline is painted. /// - public IBrush Stroke + public IBrush? Stroke { get { return GetValue(StrokeProperty); } set { SetValue(StrokeProperty, value); } @@ -150,7 +152,7 @@ namespace Avalonia.Controls.Shapes /// /// Gets or sets a collection of values that indicate the pattern of dashes and gaps that is used to outline shapes. /// - public AvaloniaList StrokeDashArray + public AvaloniaList? StrokeDashArray { get { return GetValue(StrokeDashArrayProperty); } set { SetValue(StrokeDashArrayProperty, value); } @@ -231,15 +233,16 @@ namespace Avalonia.Controls.Shapes /// Creates the shape's defining geometry. /// /// Defining of the shape. - protected abstract Geometry CreateDefiningGeometry(); + protected abstract Geometry? CreateDefiningGeometry(); /// - /// Invalidates of this shape. + /// Invalidates the geometry of this shape. /// protected void InvalidateGeometry() { _renderedGeometry = null; _definingGeometry = null; + InvalidateMeasure(); } @@ -385,8 +388,8 @@ namespace Avalonia.Controls.Shapes // portion changes. if (e.Property == BoundsProperty) { - var oldBounds = (Rect)e.OldValue; - var newBounds = (Rect)e.NewValue; + var oldBounds = (Rect)e.OldValue!; + var newBounds = (Rect)e.NewValue!; if (oldBounds.Size == newBounds.Size) {