diff --git a/src/Avalonia.Base/Animation/KeySpline.cs b/src/Avalonia.Base/Animation/KeySpline.cs
index 6ca5b2e759..ed6adb79b8 100644
--- a/src/Avalonia.Base/Animation/KeySpline.cs
+++ b/src/Avalonia.Base/Animation/KeySpline.cs
@@ -79,15 +79,12 @@ namespace Avalonia.Animation
/// culture of the string
/// Thrown if the string does not have 4 values
/// A with the appropriate values set
- public static KeySpline Parse(string value, CultureInfo culture)
+ public static KeySpline Parse(string value, CultureInfo? culture)
{
- if (culture is null)
- culture = CultureInfo.InvariantCulture;
+ culture ??= CultureInfo.InvariantCulture;
- using (var tokenizer = new StringTokenizer((string)value, culture, exceptionMessage: $"Invalid KeySpline string: \"{value}\"."))
- {
- return new KeySpline(tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble());
- }
+ using var tokenizer = new StringTokenizer(value, culture, exceptionMessage: $"Invalid KeySpline string: \"{value}\".");
+ return new KeySpline(tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble());
}
///
diff --git a/src/Avalonia.Base/AvaloniaObject.cs b/src/Avalonia.Base/AvaloniaObject.cs
index 1946d4ba5c..50a7a5c831 100644
--- a/src/Avalonia.Base/AvaloniaObject.cs
+++ b/src/Avalonia.Base/AvaloniaObject.cs
@@ -152,7 +152,7 @@ namespace Avalonia
property = property ?? throw new ArgumentNullException(nameof(property));
VerifyAccess();
- _values?.ClearLocalValue(property);
+ _values.ClearLocalValue(property);
}
///
@@ -242,7 +242,14 @@ namespace Avalonia
return registered.InvokeGetter(this);
}
- ///
+ ///
+ /// Gets an base value.
+ ///
+ /// The property.
+ ///
+ /// Gets the value of the property excluding animated values, otherwise .
+ /// Note that this method does not return property values that come from inherited or default values.
+ ///
public Optional GetBaseValue(StyledProperty property)
{
_ = property ?? throw new ArgumentNullException(nameof(property));
@@ -261,7 +268,7 @@ namespace Avalonia
VerifyAccess();
- return _values?.IsAnimating(property) ?? false;
+ return _values.IsAnimating(property);
}
///
@@ -279,7 +286,7 @@ namespace Avalonia
VerifyAccess();
- return _values?.IsSet(property) ?? false;
+ return _values.IsSet(property);
}
///
@@ -515,14 +522,12 @@ namespace Avalonia
/// The property.
public void CoerceValue(AvaloniaProperty property) => _values.CoerceValue(property);
- ///
internal void AddInheritanceChild(AvaloniaObject child)
{
_inheritanceChildren ??= new List();
_inheritanceChildren.Add(child);
}
-
- ///
+
internal void RemoveInheritanceChild(AvaloniaObject child)
{
_inheritanceChildren?.Remove(child);
@@ -541,24 +546,11 @@ namespace Avalonia
return new AvaloniaPropertyValue(
property,
GetValue(property),
- BindingPriority.Unset,
- "Local Value");
- }
- else if (_values != null)
- {
- var result = _values.GetDiagnostic(property);
-
- if (result != null)
- {
- return result;
- }
+ BindingPriority.LocalValue,
+ null);
}
- return new AvaloniaPropertyValue(
- property,
- GetValue(property),
- BindingPriority.Unset,
- "Unset");
+ return _values.GetDiagnostic(property);
}
internal ValueStore GetValueStore() => _values;
diff --git a/src/Avalonia.Base/Diagnostics/AvaloniaObjectExtensions.cs b/src/Avalonia.Base/Diagnostics/AvaloniaObjectExtensions.cs
index d7b1f2e053..270cac95f2 100644
--- a/src/Avalonia.Base/Diagnostics/AvaloniaObjectExtensions.cs
+++ b/src/Avalonia.Base/Diagnostics/AvaloniaObjectExtensions.cs
@@ -1,6 +1,3 @@
-using System;
-using Avalonia.Data;
-
namespace Avalonia.Diagnostics
{
///
diff --git a/src/Avalonia.Base/Input/DragEventArgs.cs b/src/Avalonia.Base/Input/DragEventArgs.cs
index 403dd6f23e..8d7cc2b9a1 100644
--- a/src/Avalonia.Base/Input/DragEventArgs.cs
+++ b/src/Avalonia.Base/Input/DragEventArgs.cs
@@ -1,36 +1,28 @@
using System;
using Avalonia.Interactivity;
using Avalonia.Metadata;
-using Avalonia.VisualTree;
namespace Avalonia.Input
{
public class DragEventArgs : RoutedEventArgs
{
- private Interactive _target;
- private Point _targetLocation;
+ private readonly Interactive _target;
+ private readonly Point _targetLocation;
public DragDropEffects DragEffects { get; set; }
- public IDataObject Data { get; private set; }
+ public IDataObject Data { get; }
- public KeyModifiers KeyModifiers { get; private set; }
+ public KeyModifiers KeyModifiers { get; }
public Point GetPosition(Visual relativeTo)
{
- var point = new Point(0, 0);
-
if (relativeTo == null)
{
throw new ArgumentNullException(nameof(relativeTo));
}
- if (_target != null)
- {
- point = _target.TranslatePoint(_targetLocation, relativeTo) ?? point;
- }
-
- return point;
+ return _target.TranslatePoint(_targetLocation, relativeTo) ?? new Point(0, 0);
}
[Unstable]
diff --git a/src/Avalonia.Base/Input/KeyGesture.cs b/src/Avalonia.Base/Input/KeyGesture.cs
index c6618fd550..9ee8ae9711 100644
--- a/src/Avalonia.Base/Input/KeyGesture.cs
+++ b/src/Avalonia.Base/Input/KeyGesture.cs
@@ -136,7 +136,7 @@ namespace Avalonia.Input
return StringBuilderCache.GetStringAndRelease(s);
}
- public bool Matches(KeyEventArgs keyEvent) =>
+ public bool Matches(KeyEventArgs? keyEvent) =>
keyEvent != null &&
keyEvent.KeyModifiers == KeyModifiers &&
ResolveNumPadOperationKey(keyEvent.Key) == ResolveNumPadOperationKey(Key);
diff --git a/src/Avalonia.Base/Input/KeyboardNavigationHandler.cs b/src/Avalonia.Base/Input/KeyboardNavigationHandler.cs
index b05d8f30bb..ba909de60f 100644
--- a/src/Avalonia.Base/Input/KeyboardNavigationHandler.cs
+++ b/src/Avalonia.Base/Input/KeyboardNavigationHandler.cs
@@ -1,6 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
-using System.Linq;
using Avalonia.Input.Navigation;
using Avalonia.VisualTree;
@@ -51,7 +50,7 @@ namespace Avalonia.Input
// If there's a custom keyboard navigation handler as an ancestor, use that.
var custom = (element as Visual)?.FindAncestorOfType(true);
- if (custom is object && HandlePreCustomNavigation(custom, element, direction, out var ce))
+ if (custom is not null && HandlePreCustomNavigation(custom, element, direction, out var ce))
return ce;
var result = direction switch
@@ -117,32 +116,27 @@ namespace Avalonia.Input
NavigationDirection direction,
[NotNullWhen(true)] out IInputElement? result)
{
- if (customHandler != null)
+ var (handled, next) = customHandler.GetNext(element, direction);
+
+ if (handled)
{
- var (handled, next) = customHandler.GetNext(element, direction);
+ if (next is not null)
+ {
+ result = next;
+ return true;
+ }
- if (handled)
+ var r = direction switch
{
- if (next != null)
- {
- result = next;
- return true;
- }
- else if (direction == NavigationDirection.Next || direction == NavigationDirection.Previous)
- {
- var r = direction switch
- {
- NavigationDirection.Next => TabNavigation.GetNextTabOutside(customHandler),
- NavigationDirection.Previous => TabNavigation.GetPrevTabOutside(customHandler),
- _ => throw new NotSupportedException(),
- };
-
- if (r is object)
- {
- result = r;
- return true;
- }
- }
+ NavigationDirection.Next => TabNavigation.GetNextTabOutside(customHandler),
+ NavigationDirection.Previous => TabNavigation.GetPrevTabOutside(customHandler),
+ _ => null
+ };
+
+ if (r is not null)
+ {
+ result = r;
+ return true;
}
}
diff --git a/src/Avalonia.Base/Input/Navigation/TabNavigation.cs b/src/Avalonia.Base/Input/Navigation/TabNavigation.cs
index d218867cf2..c460ecf3b3 100644
--- a/src/Avalonia.Base/Input/Navigation/TabNavigation.cs
+++ b/src/Avalonia.Base/Input/Navigation/TabNavigation.cs
@@ -1,6 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
using Avalonia.VisualTree;
namespace Avalonia.Input.Navigation
@@ -54,8 +52,7 @@ namespace Avalonia.Input.Navigation
// Avoid the endless loop here for Cycle groups
if (loopStartElement == nextTabElement)
break;
- if (loopStartElement == null)
- loopStartElement = nextTabElement;
+ loopStartElement ??= nextTabElement;
var firstTabElementInside = GetNextTab(null, nextTabElement, true);
if (firstTabElementInside != null)
@@ -80,12 +77,9 @@ namespace Avalonia.Input.Navigation
public static IInputElement? GetNextTabOutside(ICustomKeyboardNavigation e)
{
- if (e is IInputElement container)
+ if (e is IInputElement container && GetLastInTree(container) is { } last)
{
- var last = GetLastInTree(container);
-
- if (last is object)
- return GetNextTab(last, false);
+ return GetNextTab(last, false);
}
return null;
@@ -93,11 +87,8 @@ namespace Avalonia.Input.Navigation
public static IInputElement? GetPrevTab(IInputElement? e, IInputElement? container, bool goDownOnly)
{
- if (e is null && container is null)
- throw new InvalidOperationException("Either 'e' or 'container' must be non-null.");
-
- if (container is null)
- container = GetGroupParent(e!);
+ container ??=
+ GetGroupParent(e ?? throw new InvalidOperationException("Either 'e' or 'container' must be non-null."));
KeyboardNavigationMode tabbingType = GetKeyNavigationMode(container);
@@ -163,8 +154,7 @@ namespace Avalonia.Input.Navigation
// Avoid the endless loop here
if (loopStartElement == nextTabElement)
break;
- if (loopStartElement == null)
- loopStartElement = nextTabElement;
+ loopStartElement ??= nextTabElement;
// At this point nextTabElement is TabGroup
var lastTabElementInside = GetPrevTab(null, nextTabElement, true);
@@ -189,22 +179,18 @@ namespace Avalonia.Input.Navigation
public static IInputElement? GetPrevTabOutside(ICustomKeyboardNavigation e)
{
- if (e is IInputElement container)
+ if (e is IInputElement container && GetFirstChild(container) is { } first)
{
- var first = GetFirstChild(container);
-
- if (first is object)
- return GetPrevTab(first, null, false);
+ return GetPrevTab(first, null, false);
}
return null;
}
- private static IInputElement? FocusedElement(IInputElement e)
+ private static IInputElement? FocusedElement(IInputElement? e)
{
- var iie = e;
// Focus delegation is enabled only if keyboard focus is outside the container
- if (iie != null && !iie.IsKeyboardFocusWithin)
+ if (e != null && !e.IsKeyboardFocusWithin)
{
var focusedElement = (FocusManager.Instance as FocusManager)?.GetFocusedElement(e);
if (focusedElement != null)
@@ -229,13 +215,11 @@ namespace Avalonia.Input.Navigation
private static IInputElement? GetFirstChild(IInputElement e)
{
// If the element has a FocusedElement it should be its first child
- if (FocusedElement(e) is IInputElement focusedElement)
+ if (FocusedElement(e) is { } focusedElement)
return focusedElement;
// Return the first visible element.
- var uiElement = e as InputElement;
-
- if (uiElement is null || IsVisibleAndEnabled(uiElement))
+ if (e is not InputElement uiElement || IsVisibleAndEnabled(uiElement))
{
if (e is Visual elementAsVisual)
{
@@ -265,7 +249,7 @@ namespace Avalonia.Input.Navigation
private static IInputElement? GetLastChild(IInputElement e)
{
// If the element has a FocusedElement it should be its last child
- if (FocusedElement(e) is IInputElement focusedElement)
+ if (FocusedElement(e) is { } focusedElement)
return focusedElement;
// Return the last visible element.
@@ -273,9 +257,7 @@ namespace Avalonia.Input.Navigation
if (uiElement == null || IsVisibleAndEnabled(uiElement))
{
- var elementAsVisual = e as Visual;
-
- if (elementAsVisual != null)
+ if (e is Visual elementAsVisual)
{
var children = elementAsVisual.VisualChildren;
var count = children.Count;
@@ -322,7 +304,7 @@ namespace Avalonia.Input.Navigation
return firstTabElement;
}
- private static IInputElement? GetLastInTree(IInputElement container)
+ private static IInputElement GetLastInTree(IInputElement container)
{
IInputElement? result;
IInputElement? c = container;
diff --git a/src/Avalonia.Base/LogicalTree/LogicalExtensions.cs b/src/Avalonia.Base/LogicalTree/LogicalExtensions.cs
index 74720c0a77..9ab7da3ff7 100644
--- a/src/Avalonia.Base/LogicalTree/LogicalExtensions.cs
+++ b/src/Avalonia.Base/LogicalTree/LogicalExtensions.cs
@@ -48,7 +48,7 @@ namespace Avalonia.LogicalTree
/// The logical.
/// If given logical should be included in search.
/// First ancestor of given type.
- public static T? FindLogicalAncestorOfType(this ILogical logical, bool includeSelf = false) where T : class
+ public static T? FindLogicalAncestorOfType(this ILogical? logical, bool includeSelf = false) where T : class
{
if (logical is null)
{
@@ -120,7 +120,7 @@ namespace Avalonia.LogicalTree
/// The logical.
/// If given logical should be included in search.
/// First descendant of given type.
- public static T? FindLogicalDescendantOfType(this ILogical logical, bool includeSelf = false) where T : class
+ public static T? FindLogicalDescendantOfType(this ILogical? logical, bool includeSelf = false) where T : class
{
if (logical is null)
{
@@ -185,7 +185,7 @@ namespace Avalonia.LogicalTree
/// True if is an ancestor of ;
/// otherwise false.
///
- public static bool IsLogicalAncestorOf(this ILogical logical, ILogical target)
+ public static bool IsLogicalAncestorOf(this ILogical? logical, ILogical? target)
{
var current = target?.LogicalParent;
diff --git a/src/Avalonia.Base/Media/Color.cs b/src/Avalonia.Base/Media/Color.cs
index 5470a735b3..ab89177295 100644
--- a/src/Avalonia.Base/Media/Color.cs
+++ b/src/Avalonia.Base/Media/Color.cs
@@ -147,16 +147,11 @@ namespace Avalonia.Media
/// The color string.
/// The parsed color
/// The status of the operation.
- public static bool TryParse(string s, out Color color)
+ public static bool TryParse(string? s, out Color color)
{
color = default;
- if (s is null)
- {
- return false;
- }
-
- if (s.Length == 0)
+ if (string.IsNullOrEmpty(s))
{
return false;
}
diff --git a/src/Avalonia.Base/Media/DrawingContext.cs b/src/Avalonia.Base/Media/DrawingContext.cs
index d295111d72..622181dba0 100644
--- a/src/Avalonia.Base/Media/DrawingContext.cs
+++ b/src/Avalonia.Base/Media/DrawingContext.cs
@@ -240,7 +240,7 @@ namespace Avalonia.Media
///
/// The foreground brush.
/// The glyph run.
- public void DrawGlyphRun(IBrush foreground, GlyphRun glyphRun)
+ public void DrawGlyphRun(IBrush? foreground, GlyphRun glyphRun)
{
_ = glyphRun ?? throw new ArgumentNullException(nameof(glyphRun));
diff --git a/src/Avalonia.Base/Media/DrawingGroup.cs b/src/Avalonia.Base/Media/DrawingGroup.cs
index 481329c20c..b7abda2c61 100644
--- a/src/Avalonia.Base/Media/DrawingGroup.cs
+++ b/src/Avalonia.Base/Media/DrawingGroup.cs
@@ -13,14 +13,14 @@ namespace Avalonia.Media
public static readonly StyledProperty OpacityProperty =
AvaloniaProperty.Register(nameof(Opacity), 1);
- public static readonly StyledProperty TransformProperty =
- AvaloniaProperty.Register(nameof(Transform));
+ public static readonly StyledProperty TransformProperty =
+ AvaloniaProperty.Register(nameof(Transform));
- public static readonly StyledProperty ClipGeometryProperty =
- AvaloniaProperty.Register(nameof(ClipGeometry));
+ public static readonly StyledProperty ClipGeometryProperty =
+ AvaloniaProperty.Register(nameof(ClipGeometry));
- public static readonly StyledProperty OpacityMaskProperty =
- AvaloniaProperty.Register(nameof(OpacityMask));
+ public static readonly StyledProperty OpacityMaskProperty =
+ AvaloniaProperty.Register(nameof(OpacityMask));
public static readonly DirectProperty ChildrenProperty =
AvaloniaProperty.RegisterDirect(
@@ -36,19 +36,19 @@ namespace Avalonia.Media
set => SetValue(OpacityProperty, value);
}
- public Transform Transform
+ public Transform? Transform
{
get => GetValue(TransformProperty);
set => SetValue(TransformProperty, value);
}
- public Geometry ClipGeometry
+ public Geometry? ClipGeometry
{
get => GetValue(ClipGeometryProperty);
set => SetValue(ClipGeometryProperty, value);
}
- public IBrush OpacityMask
+ public IBrush? OpacityMask
{
get => GetValue(OpacityMaskProperty);
set => SetValue(OpacityMaskProperty, value);
@@ -159,7 +159,7 @@ namespace Avalonia.Media
public void DrawGeometry(IBrush? brush, IPen? pen, IGeometryImpl geometry)
{
- if (((brush == null) && (pen == null)) || (geometry == null))
+ if ((brush == null) && (pen == null))
{
return;
}
@@ -167,9 +167,9 @@ namespace Avalonia.Media
AddNewGeometryDrawing(brush, pen, new PlatformGeometry(geometry));
}
- public void DrawGlyphRun(IBrush foreground, IRef glyphRun)
+ public void DrawGlyphRun(IBrush? foreground, IRef glyphRun)
{
- if (foreground == null || glyphRun == null)
+ if (foreground == null)
{
return;
}
@@ -184,7 +184,7 @@ namespace Avalonia.Media
AddDrawing(glyphRunDrawing);
}
- public void DrawLine(IPen pen, Point p1, Point p2)
+ public void DrawLine(IPen? pen, Point p1, Point p2)
{
if (pen == null)
{
diff --git a/src/Avalonia.Base/Media/DrawingImage.cs b/src/Avalonia.Base/Media/DrawingImage.cs
index 38ddbdfaed..1b22a1ee69 100644
--- a/src/Avalonia.Base/Media/DrawingImage.cs
+++ b/src/Avalonia.Base/Media/DrawingImage.cs
@@ -20,8 +20,8 @@ namespace Avalonia.Media
///
/// Defines the property.
///
- public static readonly StyledProperty DrawingProperty =
- AvaloniaProperty.Register(nameof(Drawing));
+ public static readonly StyledProperty DrawingProperty =
+ AvaloniaProperty.Register(nameof(Drawing));
///
public event EventHandler? Invalidated;
@@ -30,7 +30,7 @@ namespace Avalonia.Media
/// Gets or sets the drawing content.
///
[Content]
- public Drawing Drawing
+ public Drawing? Drawing
{
get => GetValue(DrawingProperty);
set => SetValue(DrawingProperty, value);
diff --git a/src/Avalonia.Base/Media/FontFamily.cs b/src/Avalonia.Base/Media/FontFamily.cs
index da84861668..f4406bd010 100644
--- a/src/Avalonia.Base/Media/FontFamily.cs
+++ b/src/Avalonia.Base/Media/FontFamily.cs
@@ -119,7 +119,7 @@ namespace Avalonia.Media
case 2:
{
- var source = segments[0].StartsWith("/")
+ var source = segments[0].StartsWith("/", StringComparison.Ordinal)
? new Uri(segments[0], UriKind.Relative)
: new Uri(segments[0], UriKind.RelativeOrAbsolute);
@@ -188,7 +188,7 @@ namespace Avalonia.Media
{
unchecked
{
- return ((FamilyNames != null ? FamilyNames.GetHashCode() : 0) * 397) ^ (Key != null ? Key.GetHashCode() : 0);
+ return (FamilyNames.GetHashCode() * 397) ^ (Key is not null ? Key.GetHashCode() : 0);
}
}
diff --git a/src/Avalonia.Base/Media/Fonts/FontFamilyKey.cs b/src/Avalonia.Base/Media/Fonts/FontFamilyKey.cs
index f607c67fed..12bb7e77e7 100644
--- a/src/Avalonia.Base/Media/Fonts/FontFamilyKey.cs
+++ b/src/Avalonia.Base/Media/Fonts/FontFamilyKey.cs
@@ -41,10 +41,7 @@ namespace Avalonia.Media.Fonts
{
var hash = (int)2166136261;
- if (Source != null)
- {
- hash = (hash * 16777619) ^ Source.GetHashCode();
- }
+ hash = (hash * 16777619) ^ Source.GetHashCode();
if (BaseUri != null)
{
diff --git a/src/Avalonia.Base/Media/FormattedText.cs b/src/Avalonia.Base/Media/FormattedText.cs
index 28757b1a1d..3b63a98720 100644
--- a/src/Avalonia.Base/Media/FormattedText.cs
+++ b/src/Avalonia.Base/Media/FormattedText.cs
@@ -1354,7 +1354,7 @@ namespace Avalonia.Media
{
var highlightBounds = currentLine.GetTextBounds(x0,x1 - x0);
- if (highlightBounds != null)
+ if (highlightBounds.Count > 0)
{
foreach (var bound in highlightBounds)
{
@@ -1365,7 +1365,7 @@ namespace Avalonia.Media
// Convert logical units (which extend leftward from the right edge
// of the paragraph) to physical units.
//
- // Note that since rect is in logical units, rect.Right corresponds to
+ // Note that since rect is in logical units, rect.Right corresponds to
// the visual *left* edge of the rectangle in the RTL case. Specifically,
// is the distance leftward from the right edge of the formatting rectangle
// whose width is the paragraph width passed to FormatLine.
@@ -1384,7 +1384,7 @@ namespace Avalonia.Media
else
{
accumulatedBounds = Geometry.Combine(accumulatedBounds, rectangleGeometry, GeometryCombineMode.Union);
- }
+ }
}
}
}
diff --git a/src/Avalonia.Base/Media/GeometryDrawing.cs b/src/Avalonia.Base/Media/GeometryDrawing.cs
index 26cc2c3cab..ac2dce1e42 100644
--- a/src/Avalonia.Base/Media/GeometryDrawing.cs
+++ b/src/Avalonia.Base/Media/GeometryDrawing.cs
@@ -15,8 +15,8 @@ namespace Avalonia.Media
///
/// Defines the property.
///
- public static readonly StyledProperty GeometryProperty =
- AvaloniaProperty.Register(nameof(Geometry));
+ public static readonly StyledProperty GeometryProperty =
+ AvaloniaProperty.Register(nameof(Geometry));
///
/// Defines the property.
@@ -34,7 +34,7 @@ namespace Avalonia.Media
/// Gets or sets the that describes the shape of this .
///
[Content]
- public Geometry Geometry
+ public Geometry? Geometry
{
get => GetValue(GeometryProperty);
set => SetValue(GeometryProperty, value);
diff --git a/src/Avalonia.Base/Media/GlyphRunDrawing.cs b/src/Avalonia.Base/Media/GlyphRunDrawing.cs
index 242b9913fa..06d92fd81c 100644
--- a/src/Avalonia.Base/Media/GlyphRunDrawing.cs
+++ b/src/Avalonia.Base/Media/GlyphRunDrawing.cs
@@ -2,19 +2,19 @@
{
public class GlyphRunDrawing : Drawing
{
- public static readonly StyledProperty ForegroundProperty =
- AvaloniaProperty.Register(nameof(Foreground));
+ public static readonly StyledProperty ForegroundProperty =
+ AvaloniaProperty.Register(nameof(Foreground));
- public static readonly StyledProperty GlyphRunProperty =
- AvaloniaProperty.Register(nameof(GlyphRun));
+ public static readonly StyledProperty GlyphRunProperty =
+ AvaloniaProperty.Register(nameof(GlyphRun));
- public IBrush Foreground
+ public IBrush? Foreground
{
get => GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
- public GlyphRun GlyphRun
+ public GlyphRun? GlyphRun
{
get => GetValue(GlyphRunProperty);
set => SetValue(GlyphRunProperty, value);
diff --git a/src/Avalonia.Base/Media/HslColor.cs b/src/Avalonia.Base/Media/HslColor.cs
index 425a3138c3..b4bf6fd217 100644
--- a/src/Avalonia.Base/Media/HslColor.cs
+++ b/src/Avalonia.Base/Media/HslColor.cs
@@ -254,7 +254,7 @@ namespace Avalonia.Media
/// The HSL color string to parse.
/// The parsed .
/// True if parsing was successful; otherwise, false.
- public static bool TryParse(string s, out HslColor hslColor)
+ public static bool TryParse(string? s, out HslColor hslColor)
{
bool prefixMatched = false;
diff --git a/src/Avalonia.Base/Media/HsvColor.cs b/src/Avalonia.Base/Media/HsvColor.cs
index 9f95b31518..f97457c54d 100644
--- a/src/Avalonia.Base/Media/HsvColor.cs
+++ b/src/Avalonia.Base/Media/HsvColor.cs
@@ -254,7 +254,7 @@ namespace Avalonia.Media
/// The HSV color string to parse.
/// The parsed .
/// True if parsing was successful; otherwise, false.
- public static bool TryParse(string s, out HsvColor hsvColor)
+ public static bool TryParse(string? s, out HsvColor hsvColor)
{
bool prefixMatched = false;
diff --git a/src/Avalonia.Base/Media/IVisualBrush.cs b/src/Avalonia.Base/Media/IVisualBrush.cs
index 6662613ff4..a7d3e4da10 100644
--- a/src/Avalonia.Base/Media/IVisualBrush.cs
+++ b/src/Avalonia.Base/Media/IVisualBrush.cs
@@ -1,5 +1,4 @@
using Avalonia.Metadata;
-using Avalonia.VisualTree;
namespace Avalonia.Media
{
@@ -12,6 +11,6 @@ namespace Avalonia.Media
///
/// Gets the visual to draw.
///
- Visual Visual { get; }
+ Visual? Visual { get; }
}
}
diff --git a/src/Avalonia.Base/Media/Immutable/ImmutableDashStyle.cs b/src/Avalonia.Base/Media/Immutable/ImmutableDashStyle.cs
index 1f53f06955..6dff006045 100644
--- a/src/Avalonia.Base/Media/Immutable/ImmutableDashStyle.cs
+++ b/src/Avalonia.Base/Media/Immutable/ImmutableDashStyle.cs
@@ -39,17 +39,8 @@ namespace Avalonia.Media.Immutable
{
return true;
}
- else if (other is null)
- {
- return false;
- }
- if (Offset != other.Offset)
- {
- return false;
- }
-
- return SequenceEqual(Dashes, other.Dashes);
+ return other is not null && Offset == other.Offset && SequenceEqual(_dashes, other.Dashes);
}
///
@@ -58,30 +49,27 @@ namespace Avalonia.Media.Immutable
var hashCode = 717868523;
hashCode = hashCode * -1521134295 + Offset.GetHashCode();
- if (_dashes != null)
+ foreach (var i in _dashes)
{
- foreach (var i in _dashes)
- {
- hashCode = hashCode * -1521134295 + i.GetHashCode();
- }
+ hashCode = hashCode * -1521134295 + i.GetHashCode();
}
return hashCode;
}
- private static bool SequenceEqual(IReadOnlyList left, IReadOnlyList? right)
+ private static bool SequenceEqual(double[] left, IReadOnlyList? right)
{
if (ReferenceEquals(left, right))
{
return true;
}
- if (left == null || right == null || left.Count != right.Count)
+ if (right is null || left.Length != right.Count)
{
return false;
}
- for (var c = 0; c < left.Count; c++)
+ for (var c = 0; c < left.Length; c++)
{
if (left[c] != right[c])
{
diff --git a/src/Avalonia.Base/Media/Immutable/ImmutableVisualBrush.cs b/src/Avalonia.Base/Media/Immutable/ImmutableVisualBrush.cs
index 9b443391c5..0b625080e3 100644
--- a/src/Avalonia.Base/Media/Immutable/ImmutableVisualBrush.cs
+++ b/src/Avalonia.Base/Media/Immutable/ImmutableVisualBrush.cs
@@ -1,5 +1,4 @@
using Avalonia.Media.Imaging;
-using Avalonia.VisualTree;
namespace Avalonia.Media.Immutable
{
@@ -31,11 +30,11 @@ namespace Avalonia.Media.Immutable
RelativeRect? destinationRect = null,
double opacity = 1,
ImmutableTransform? transform = null,
- RelativePoint transformOrigin = new RelativePoint(),
+ RelativePoint transformOrigin = default,
RelativeRect? sourceRect = null,
Stretch stretch = Stretch.Uniform,
TileMode tileMode = TileMode.None,
- Imaging.BitmapInterpolationMode bitmapInterpolationMode = Imaging.BitmapInterpolationMode.Default)
+ BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default)
: base(
alignmentX,
alignmentY,
@@ -62,6 +61,6 @@ namespace Avalonia.Media.Immutable
}
///
- public Visual Visual { get; }
+ public Visual? Visual { get; }
}
}
diff --git a/src/Avalonia.Base/Media/TextDecoration.cs b/src/Avalonia.Base/Media/TextDecoration.cs
index dc9e5cb907..b74b7df9c5 100644
--- a/src/Avalonia.Base/Media/TextDecoration.cs
+++ b/src/Avalonia.Base/Media/TextDecoration.cs
@@ -22,8 +22,8 @@ namespace Avalonia.Media
///
/// Defines the property.
///
- public static readonly StyledProperty StrokeProperty =
- AvaloniaProperty.Register(nameof(Stroke));
+ public static readonly StyledProperty StrokeProperty =
+ AvaloniaProperty.Register(nameof(Stroke));
///
/// Defines the property.
@@ -34,8 +34,8 @@ namespace Avalonia.Media
///
/// Defines the property.
///
- public static readonly StyledProperty> StrokeDashArrayProperty =
- AvaloniaProperty.Register>(nameof(StrokeDashArray));
+ public static readonly StyledProperty?> StrokeDashArrayProperty =
+ AvaloniaProperty.Register?>(nameof(StrokeDashArray));
///
/// Defines the property.
@@ -82,7 +82,7 @@ namespace Avalonia.Media
///
/// Gets or sets the that specifies how the is painted.
///
- public IBrush Stroke
+ public IBrush? Stroke
{
get { return GetValue(StrokeProperty); }
set { SetValue(StrokeProperty, value); }
@@ -101,7 +101,7 @@ namespace Avalonia.Media
/// Gets or sets a collection of values that indicate the pattern of dashes and gaps
/// that is used to draw the .
///
- public AvaloniaList StrokeDashArray
+ public AvaloniaList? StrokeDashArray
{
get { return GetValue(StrokeDashArrayProperty); }
set { SetValue(StrokeDashArrayProperty, value); }
@@ -220,7 +220,7 @@ namespace Avalonia.Media
var intersections = glyphRun.PlatformImpl.Item.GetIntersections((float)(thickness * 0.5d - offsetY), (float)(thickness * 1.5d - offsetY));
- if (intersections != null && intersections.Count > 0)
+ if (intersections.Count > 0)
{
var last = baselineOrigin.X;
var finalPos = last + glyphRun.Size.Width;
diff --git a/src/Avalonia.Base/Media/VisualBrush.cs b/src/Avalonia.Base/Media/VisualBrush.cs
index 1261d233ac..2be3e9a94e 100644
--- a/src/Avalonia.Base/Media/VisualBrush.cs
+++ b/src/Avalonia.Base/Media/VisualBrush.cs
@@ -1,5 +1,4 @@
using Avalonia.Media.Immutable;
-using Avalonia.VisualTree;
namespace Avalonia.Media
{
@@ -11,8 +10,8 @@ namespace Avalonia.Media
///
/// Defines the property.
///
- public static readonly StyledProperty VisualProperty =
- AvaloniaProperty.Register(nameof(Visual));
+ public static readonly StyledProperty VisualProperty =
+ AvaloniaProperty.Register(nameof(Visual));
static VisualBrush()
{
@@ -38,7 +37,7 @@ namespace Avalonia.Media
///
/// Gets or sets the visual to draw.
///
- public Visual Visual
+ public Visual? Visual
{
get { return GetValue(VisualProperty); }
set { SetValue(VisualProperty, value); }
diff --git a/src/Avalonia.Base/Platform/IDrawingContextImpl.cs b/src/Avalonia.Base/Platform/IDrawingContextImpl.cs
index c05c04c22e..8509067cd0 100644
--- a/src/Avalonia.Base/Platform/IDrawingContextImpl.cs
+++ b/src/Avalonia.Base/Platform/IDrawingContextImpl.cs
@@ -49,7 +49,7 @@ namespace Avalonia.Platform
/// The stroke pen.
/// The first point of the line.
/// The second point of the line.
- void DrawLine(IPen pen, Point p1, Point p2);
+ void DrawLine(IPen? pen, Point p1, Point p2);
///
/// Draws a geometry.
@@ -91,7 +91,7 @@ namespace Avalonia.Platform
///
/// The foreground.
/// The glyph run.
- void DrawGlyphRun(IBrush foreground, IRef glyphRun);
+ void DrawGlyphRun(IBrush? foreground, IRef glyphRun);
///
/// Creates a new that can be used as a render layer
diff --git a/src/Avalonia.Base/Platform/Internal/AssemblyDescriptor.cs b/src/Avalonia.Base/Platform/Internal/AssemblyDescriptor.cs
index 467cd530fc..d1a803fefb 100644
--- a/src/Avalonia.Base/Platform/Internal/AssemblyDescriptor.cs
+++ b/src/Avalonia.Base/Platform/Internal/AssemblyDescriptor.cs
@@ -19,25 +19,20 @@ internal class AssemblyDescriptor : IAssemblyDescriptor
public AssemblyDescriptor(Assembly assembly)
{
Assembly = assembly;
+ Resources = assembly.GetManifestResourceNames()
+ .ToDictionary(n => n, n => (IAssetDescriptor)new AssemblyResourceDescriptor(assembly, n));
+ Name = assembly.GetName().Name;
- if (assembly != null)
+ using var resources = assembly.GetManifestResourceStream(Constants.AvaloniaResourceName);
+ if (resources != null)
{
- Resources = assembly.GetManifestResourceNames()
- .ToDictionary(n => n, n => (IAssetDescriptor)new AssemblyResourceDescriptor(assembly, n));
- Name = assembly.GetName().Name;
- using (var resources = assembly.GetManifestResourceStream(Constants.AvaloniaResourceName))
- {
- if (resources != null)
- {
- Resources.Remove(Constants.AvaloniaResourceName);
+ Resources.Remove(Constants.AvaloniaResourceName);
- var indexLength = new BinaryReader(resources).ReadInt32();
- var index = AvaloniaResourcesIndexReaderWriter.ReadIndex(new SlicedStream(resources, 4, indexLength));
- var baseOffset = indexLength + 4;
- AvaloniaResources = index.ToDictionary(r => GetPathRooted(r), r => (IAssetDescriptor)
- new AvaloniaResourceDescriptor(assembly, baseOffset + r.Offset, r.Size));
- }
- }
+ var indexLength = new BinaryReader(resources).ReadInt32();
+ var index = AvaloniaResourcesIndexReaderWriter.ReadIndex(new SlicedStream(resources, 4, indexLength));
+ var baseOffset = indexLength + 4;
+ AvaloniaResources = index.ToDictionary(GetPathRooted, r => (IAssetDescriptor)
+ new AvaloniaResourceDescriptor(assembly, baseOffset + r.Offset, r.Size));
}
}
@@ -45,6 +40,7 @@ internal class AssemblyDescriptor : IAssemblyDescriptor
public Dictionary? Resources { get; }
public Dictionary? AvaloniaResources { get; }
public string? Name { get; }
+
private static string GetPathRooted(AvaloniaResourcesIndexEntry r) =>
r.Path![0] == '/' ? r.Path : '/' + r.Path;
}
diff --git a/src/Avalonia.Base/Rendering/Composition/Animations/CompositionAnimation.cs b/src/Avalonia.Base/Rendering/Composition/Animations/CompositionAnimation.cs
index a6db4330a3..455e9ebb5f 100644
--- a/src/Avalonia.Base/Rendering/Composition/Animations/CompositionAnimation.cs
+++ b/src/Avalonia.Base/Rendering/Composition/Animations/CompositionAnimation.cs
@@ -23,7 +23,7 @@ namespace Avalonia.Rendering.Composition.Animations
public abstract class CompositionAnimation : CompositionObject, ICompositionAnimationBase
{
private readonly CompositionPropertySet _propertySet;
- internal CompositionAnimation(Compositor compositor) : base(compositor, null!)
+ internal CompositionAnimation(Compositor compositor) : base(compositor, null)
{
_propertySet = new CompositionPropertySet(compositor);
}
diff --git a/src/Avalonia.Base/Rendering/Composition/Animations/CompositionAnimationGroup.cs b/src/Avalonia.Base/Rendering/Composition/Animations/CompositionAnimationGroup.cs
index bad3991f43..1500e88abe 100644
--- a/src/Avalonia.Base/Rendering/Composition/Animations/CompositionAnimationGroup.cs
+++ b/src/Avalonia.Base/Rendering/Composition/Animations/CompositionAnimationGroup.cs
@@ -19,7 +19,7 @@ namespace Avalonia.Rendering.Composition.Animations
public void Remove(CompositionAnimation value) => Animations.Remove(value);
public void RemoveAll() => Animations.Clear();
- public CompositionAnimationGroup(Compositor compositor) : base(compositor, null!)
+ public CompositionAnimationGroup(Compositor compositor) : base(compositor, null)
{
}
}
diff --git a/src/Avalonia.Base/Rendering/Composition/Animations/ImplicitAnimationCollection.cs b/src/Avalonia.Base/Rendering/Composition/Animations/ImplicitAnimationCollection.cs
index 72be4edd07..d9adf261f8 100644
--- a/src/Avalonia.Base/Rendering/Composition/Animations/ImplicitAnimationCollection.cs
+++ b/src/Avalonia.Base/Rendering/Composition/Animations/ImplicitAnimationCollection.cs
@@ -23,7 +23,7 @@ namespace Avalonia.Rendering.Composition.Animations
{
private Dictionary _inner = new Dictionary();
private IDictionary _innerface;
- internal ImplicitAnimationCollection(Compositor compositor) : base(compositor, null!)
+ internal ImplicitAnimationCollection(Compositor compositor) : base(compositor, null)
{
_innerface = _inner;
}
diff --git a/src/Avalonia.Base/Rendering/Composition/CompositionDrawingSurface.cs b/src/Avalonia.Base/Rendering/Composition/CompositionDrawingSurface.cs
index ab4329df62..bfe70d593d 100644
--- a/src/Avalonia.Base/Rendering/Composition/CompositionDrawingSurface.cs
+++ b/src/Avalonia.Base/Rendering/Composition/CompositionDrawingSurface.cs
@@ -1,4 +1,3 @@
-using System;
using System.Threading.Tasks;
using Avalonia.Rendering.Composition.Server;
using Avalonia.Threading;
@@ -7,7 +6,7 @@ namespace Avalonia.Rendering.Composition;
public class CompositionDrawingSurface : CompositionSurface
{
- internal new ServerCompositionDrawingSurface Server => (ServerCompositionDrawingSurface)base.Server;
+ internal new ServerCompositionDrawingSurface Server => (ServerCompositionDrawingSurface)base.Server!;
internal CompositionDrawingSurface(Compositor compositor) : base(compositor, new ServerCompositionDrawingSurface(compositor.Server))
{
}
diff --git a/src/Avalonia.Base/Rendering/Composition/CompositionObject.cs b/src/Avalonia.Base/Rendering/Composition/CompositionObject.cs
index 50332926ad..8c21b534db 100644
--- a/src/Avalonia.Base/Rendering/Composition/CompositionObject.cs
+++ b/src/Avalonia.Base/Rendering/Composition/CompositionObject.cs
@@ -22,7 +22,7 @@ namespace Avalonia.Rendering.Composition
public ImplicitAnimationCollection? ImplicitAnimations { get; set; }
private protected InlineDictionary PendingAnimations;
- internal CompositionObject(Compositor compositor, ServerObject server)
+ internal CompositionObject(Compositor compositor, ServerObject? server)
{
Compositor = compositor;
Server = server;
@@ -32,7 +32,7 @@ namespace Avalonia.Rendering.Composition
/// The associated Compositor
///
public Compositor Compositor { get; }
- internal ServerObject Server { get; }
+ internal ServerObject? Server { get; }
public bool IsDisposed { get; private set; }
private bool _registeredForSerialization;
diff --git a/src/Avalonia.Base/Rendering/Composition/CompositionPropertySet.cs b/src/Avalonia.Base/Rendering/Composition/CompositionPropertySet.cs
index 7d794af9a2..efd89951bb 100644
--- a/src/Avalonia.Base/Rendering/Composition/CompositionPropertySet.cs
+++ b/src/Avalonia.Base/Rendering/Composition/CompositionPropertySet.cs
@@ -23,7 +23,7 @@ namespace Avalonia.Rendering.Composition
private readonly Dictionary _variants = new Dictionary();
private readonly Dictionary _objects = new Dictionary();
- internal CompositionPropertySet(Compositor compositor) : base(compositor, null!)
+ internal CompositionPropertySet(Compositor compositor) : base(compositor, null)
{
}
diff --git a/src/Avalonia.Base/Rendering/Composition/Drawing/CompositionDrawingContext.cs b/src/Avalonia.Base/Rendering/Composition/Drawing/CompositionDrawingContext.cs
index 05488a558f..b75d080cfd 100644
--- a/src/Avalonia.Base/Rendering/Composition/Drawing/CompositionDrawingContext.cs
+++ b/src/Avalonia.Base/Rendering/Composition/Drawing/CompositionDrawingContext.cs
@@ -88,8 +88,13 @@ internal class CompositionDrawingContext : IDrawingContextImpl, IDrawingContextW
}
///
- public void DrawLine(IPen pen, Point p1, Point p2)
+ public void DrawLine(IPen? pen, Point p1, Point p2)
{
+ if (pen is null)
+ {
+ return;
+ }
+
var next = NextDrawAs();
if (next == null || !next.Item.Equals(Transform, pen, p1, p2))
@@ -159,8 +164,13 @@ internal class CompositionDrawingContext : IDrawingContextImpl, IDrawingContextW
public object? GetFeature(Type t) => null;
///
- public void DrawGlyphRun(IBrush foreground, IRef glyphRun)
+ public void DrawGlyphRun(IBrush? foreground, IRef glyphRun)
{
+ if (foreground is null)
+ {
+ return;
+ }
+
var next = NextDrawAs();
if (next == null || !next.Item.Equals(Transform, foreground, glyphRun))
diff --git a/src/Avalonia.Base/Rendering/Composition/Expressions/Expression.cs b/src/Avalonia.Base/Rendering/Composition/Expressions/Expression.cs
index 560ee05c10..b15da5d05d 100644
--- a/src/Avalonia.Base/Rendering/Composition/Expressions/Expression.cs
+++ b/src/Avalonia.Base/Rendering/Composition/Expressions/Expression.cs
@@ -165,8 +165,6 @@ namespace Avalonia.Rendering.Composition.Expressions
public override ExpressionVariant Evaluate(ref ExpressionEvaluationContext context)
{
- if (context.ForeignFunctionInterface == null)
- return default;
var args = new List();
foreach (var expr in Parameters)
args.Add(expr.Evaluate(ref context));
diff --git a/src/Avalonia.Base/Rendering/Composition/Expressions/ExpressionEvaluationContext.cs b/src/Avalonia.Base/Rendering/Composition/Expressions/ExpressionEvaluationContext.cs
index 9086c59aad..f268364b54 100644
--- a/src/Avalonia.Base/Rendering/Composition/Expressions/ExpressionEvaluationContext.cs
+++ b/src/Avalonia.Base/Rendering/Composition/Expressions/ExpressionEvaluationContext.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
-using Avalonia.Rendering.Composition.Server;
// Special license applies License.md
diff --git a/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs b/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs
index c58beebe7f..50df8bd32b 100644
--- a/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs
+++ b/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs
@@ -66,7 +66,7 @@ internal class CompositorDrawingContextProxy : IDrawingContextImpl, IDrawingCont
_impl.DrawBitmap(source, opacityMask, opacityMaskRect, destRect);
}
- public void DrawLine(IPen pen, Point p1, Point p2)
+ public void DrawLine(IPen? pen, Point p1, Point p2)
{
_impl.DrawLine(pen, p1, p2);
}
@@ -86,7 +86,7 @@ internal class CompositorDrawingContextProxy : IDrawingContextImpl, IDrawingCont
_impl.DrawEllipse(brush, pen, rect);
}
- public void DrawGlyphRun(IBrush foreground, IRef glyphRun)
+ public void DrawGlyphRun(IBrush? foreground, IRef glyphRun)
{
_impl.DrawGlyphRun(foreground, glyphRun);
}
diff --git a/src/Avalonia.Base/Rendering/ImmediateRenderer.cs b/src/Avalonia.Base/Rendering/ImmediateRenderer.cs
index c67ac7057d..8e5dc38317 100644
--- a/src/Avalonia.Base/Rendering/ImmediateRenderer.cs
+++ b/src/Avalonia.Base/Rendering/ImmediateRenderer.cs
@@ -48,8 +48,10 @@ namespace Avalonia.Rendering
///
void IVisualBrushRenderer.RenderVisualBrush(IDrawingContextImpl context, IVisualBrush brush)
{
- var visual = brush.Visual;
- Render(new DrawingContext(context), visual, visual.Bounds);
+ if (brush.Visual is { } visual)
+ {
+ Render(new DrawingContext(context), visual, visual.Bounds);
+ }
}
internal static void Render(Visual visual, DrawingContext context, bool updateTransformedBounds)
diff --git a/src/Avalonia.Base/Rendering/SceneGraph/ExperimentalAcrylicNode.cs b/src/Avalonia.Base/Rendering/SceneGraph/ExperimentalAcrylicNode.cs
index 12b67105e9..82f8fc2d56 100644
--- a/src/Avalonia.Base/Rendering/SceneGraph/ExperimentalAcrylicNode.cs
+++ b/src/Avalonia.Base/Rendering/SceneGraph/ExperimentalAcrylicNode.cs
@@ -80,11 +80,8 @@ namespace Avalonia.Rendering.SceneGraph
{
p *= Transform.Invert();
- if (Material != null)
- {
- var rect = Rect.Rect;
- return rect.ContainsExclusive(p);
- }
+ var rect = Rect.Rect;
+ return rect.ContainsExclusive(p);
}
return false;
diff --git a/src/Avalonia.Base/Utilities/TypeUtilities.cs b/src/Avalonia.Base/Utilities/TypeUtilities.cs
index 3c44dd63ce..fafafabd82 100644
--- a/src/Avalonia.Base/Utilities/TypeUtilities.cs
+++ b/src/Avalonia.Base/Utilities/TypeUtilities.cs
@@ -212,7 +212,7 @@ namespace Avalonia.Utilities
var toTypeConverter = TypeDescriptor.GetConverter(toUnderl);
- if (toTypeConverter.CanConvertFrom(from) == true)
+ if (toTypeConverter.CanConvertFrom(from))
{
result = toTypeConverter.ConvertFrom(null, culture, value);
return true;
@@ -220,7 +220,7 @@ namespace Avalonia.Utilities
var fromTypeConverter = TypeDescriptor.GetConverter(from);
- if (fromTypeConverter.CanConvertTo(toUnderl) == true)
+ if (fromTypeConverter.CanConvertTo(toUnderl))
{
result = fromTypeConverter.ConvertTo(null, culture, value, toUnderl);
return true;
@@ -329,7 +329,7 @@ namespace Avalonia.Utilities
}
[RequiresUnreferencedCode(TrimmingMessages.ImplicitTypeConvertionRequiresUnreferencedCodeMessage)]
- public static T ConvertImplicit(object value)
+ public static T ConvertImplicit(object? value)
{
if (TryConvertImplicit(typeof(T), value, out var result))
{
@@ -369,11 +369,6 @@ namespace Avalonia.Utilities
///
public static bool IsNumeric(Type type)
{
- if (type == null)
- {
- return false;
- }
-
var underlyingType = Nullable.GetUnderlyingType(type);
if (underlyingType != null)
diff --git a/src/Avalonia.Base/Utilities/WeakEvent.cs b/src/Avalonia.Base/Utilities/WeakEvent.cs
index e72606bf70..237a491615 100644
--- a/src/Avalonia.Base/Utilities/WeakEvent.cs
+++ b/src/Avalonia.Base/Utilities/WeakEvent.cs
@@ -1,8 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using System.Reflection;
using System.Runtime.CompilerServices;
using Avalonia.Threading;
@@ -15,7 +11,7 @@ public class WeakEvent : WeakEvent where TEventArgs : Event
{
private readonly Func, Action> _subscribe;
- readonly ConditionalWeakTable