diff --git a/src/Avalonia.Diagnostics/Avalonia.Diagnostics.csproj b/src/Avalonia.Diagnostics/Avalonia.Diagnostics.csproj
index db8684747d..35de491668 100644
--- a/src/Avalonia.Diagnostics/Avalonia.Diagnostics.csproj
+++ b/src/Avalonia.Diagnostics/Avalonia.Diagnostics.csproj
@@ -3,12 +3,16 @@
netstandard2.0
Avalonia
Avalonia.Diagnostics
+ enable
%(Filename)
+
+
+
diff --git a/src/Avalonia.Diagnostics/Diagnostics/Controls/ThicknessEditor.cs b/src/Avalonia.Diagnostics/Diagnostics/Controls/ThicknessEditor.cs
index e5b3b080e2..cb98fb70f3 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/Controls/ThicknessEditor.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/Controls/ThicknessEditor.cs
@@ -10,8 +10,8 @@ namespace Avalonia.Diagnostics.Controls
AvaloniaProperty.RegisterDirect(nameof(Thickness), o => o.Thickness,
(o, v) => o.Thickness = v, defaultBindingMode: BindingMode.TwoWay);
- public static readonly DirectProperty HeaderProperty =
- AvaloniaProperty.RegisterDirect(nameof(Header), o => o.Header,
+ public static readonly DirectProperty HeaderProperty =
+ AvaloniaProperty.RegisterDirect(nameof(Header), o => o.Header,
(o, v) => o.Header = v);
public static readonly DirectProperty IsPresentProperty =
@@ -36,7 +36,7 @@ namespace Avalonia.Diagnostics.Controls
AvaloniaProperty.Register(nameof(Highlight));
private Thickness _thickness;
- private string _header;
+ private string? _header;
private bool _isPresent = true;
private double _left;
private double _top;
@@ -50,7 +50,7 @@ namespace Avalonia.Diagnostics.Controls
set => SetAndRaise(ThicknessProperty, ref _thickness, value);
}
- public string Header
+ public string? Header
{
get => _header;
set => SetAndRaise(HeaderProperty, ref _header, value);
diff --git a/src/Avalonia.Diagnostics/Diagnostics/Converters/BoolToOpacityConverter.cs b/src/Avalonia.Diagnostics/Diagnostics/Converters/BoolToOpacityConverter.cs
index 63ac3ab62f..0b9044e65e 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/Converters/BoolToOpacityConverter.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/Converters/BoolToOpacityConverter.cs
@@ -8,12 +8,17 @@ namespace Avalonia.Diagnostics.Converters
{
public double Opacity { get; set; }
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
- return (bool)value ? 1d : Opacity;
+ if (value is bool boolean && boolean)
+ {
+ return 1d;
+ }
+
+ return Opacity;
}
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
diff --git a/src/Avalonia.Diagnostics/Diagnostics/Converters/EnumToCheckedConverter.cs b/src/Avalonia.Diagnostics/Diagnostics/Converters/EnumToCheckedConverter.cs
index 8d10981ba7..4863782f44 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/Converters/EnumToCheckedConverter.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/Converters/EnumToCheckedConverter.cs
@@ -7,12 +7,12 @@ namespace Avalonia.Diagnostics.Converters
{
internal class EnumToCheckedConverter : IValueConverter
{
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return Equals(value, parameter);
}
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool isChecked && isChecked)
{
diff --git a/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs b/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs
index 7942d22962..78e808595f 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs
@@ -6,8 +6,6 @@ using Avalonia.Diagnostics.Views;
using Avalonia.Input;
using Avalonia.Interactivity;
-#nullable enable
-
namespace Avalonia.Diagnostics
{
public static class DevTools
@@ -74,7 +72,7 @@ namespace Avalonia.Diagnostics
private static void DevToolsClosed(object sender, EventArgs e)
{
var window = (MainWindow)sender;
- s_open.Remove(window.Root);
+ s_open.Remove(window.Root!);
window.Closed -= DevToolsClosed;
}
}
diff --git a/src/Avalonia.Diagnostics/Diagnostics/Models/ConsoleContext.cs b/src/Avalonia.Diagnostics/Diagnostics/Models/ConsoleContext.cs
index 5927bd785e..4f4579c7d9 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/Models/ConsoleContext.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/Models/ConsoleContext.cs
@@ -22,8 +22,8 @@ The following commands are available:
clear(): Clear the output history
";
- public dynamic e { get; internal set; }
- public dynamic root { get; internal set; }
+ public dynamic? e { get; internal set; }
+ public dynamic? root { get; internal set; }
internal static object NoOutput { get; } = new object();
diff --git a/src/Avalonia.Diagnostics/Diagnostics/Models/EventChainLink.cs b/src/Avalonia.Diagnostics/Diagnostics/Models/EventChainLink.cs
index 36fe12d89c..4f493bdcc2 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/Models/EventChainLink.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/Models/EventChainLink.cs
@@ -7,9 +7,7 @@ namespace Avalonia.Diagnostics.Models
{
public EventChainLink(object handler, bool handled, RoutingStrategies route)
{
- Contract.Requires(handler != null);
-
- Handler = handler;
+ Handler = handler ?? throw new ArgumentNullException(nameof(handler));
Handled = handled;
Route = route;
}
diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs
index a9353eba8b..21265f2cfc 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs
@@ -1,5 +1,4 @@
-using System.ComponentModel;
-using Avalonia.Collections;
+using System.Diagnostics.CodeAnalysis;
namespace Avalonia.Diagnostics.ViewModels
{
@@ -7,7 +6,7 @@ namespace Avalonia.Diagnostics.ViewModels
{
private readonly AvaloniaObject _target;
private string _type;
- private object _value;
+ private object? _value;
private string _priority;
private string _group;
@@ -20,12 +19,6 @@ namespace Avalonia.Diagnostics.ViewModels
$"[{property.OwnerType.Name}.{property.Name}]" :
property.Name;
- if (property.IsDirect)
- {
- _group = "Properties";
- Priority = "Direct";
- }
-
Update();
}
@@ -34,11 +27,7 @@ namespace Avalonia.Diagnostics.ViewModels
public override string Name { get; }
public bool IsAttached => Property.IsAttached;
- public string Priority
- {
- get => _priority;
- private set => RaiseAndSetIfChanged(ref _priority, value);
- }
+ public string Priority => _priority;
public override string Type => _type;
@@ -56,40 +45,37 @@ namespace Avalonia.Diagnostics.ViewModels
}
}
- public override string Group
- {
- get => _group;
- }
+ public override string Group => _group;
+ [MemberNotNull(nameof(_type), nameof(_group), nameof(_priority))]
public override void Update()
{
if (Property.IsDirect)
{
RaiseAndSetIfChanged(ref _value, _target.GetValue(Property), nameof(Value));
- RaiseAndSetIfChanged(ref _type, _value?.GetType().Name, nameof(Type));
+ RaiseAndSetIfChanged(ref _type, _value?.GetType().Name ?? Property.PropertyType.Name, nameof(Type));
+ RaiseAndSetIfChanged(ref _priority, "Direct", nameof(Priority));
+
+ _group = "Properties";
}
else
{
var val = _target.GetDiagnostic(Property);
RaiseAndSetIfChanged(ref _value, val?.Value, nameof(Value));
- RaiseAndSetIfChanged(ref _type, _value?.GetType().Name, nameof(Type));
+ RaiseAndSetIfChanged(ref _type, _value?.GetType().Name ?? Property.PropertyType.Name, nameof(Type));
if (val != null)
{
- SetGroup(IsAttached ? "Attached Properties" : "Properties");
- Priority = val.Priority.ToString();
+ RaiseAndSetIfChanged(ref _priority, val.Priority.ToString(), nameof(Priority));
+ RaiseAndSetIfChanged(ref _group, IsAttached ? "Attached Properties" : "Properties", nameof(Group));
}
else
{
- SetGroup(Priority = "Unset");
+ RaiseAndSetIfChanged(ref _priority, "Unset", nameof(Priority));
+ RaiseAndSetIfChanged(ref _group, "Unset", nameof(Group));
}
}
}
-
- private void SetGroup(string group)
- {
- RaiseAndSetIfChanged(ref _group, group, nameof(Group));
- }
}
}
diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs
index af5e254204..19e4a702eb 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs
@@ -1,4 +1,4 @@
-using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
namespace Avalonia.Diagnostics.ViewModels
@@ -7,7 +7,7 @@ namespace Avalonia.Diagnostics.ViewModels
{
private readonly object _target;
private string _type;
- private object _value;
+ private object? _value;
public ClrPropertyViewModel(object o, PropertyInfo property)
{
@@ -47,11 +47,12 @@ namespace Avalonia.Diagnostics.ViewModels
}
}
+ [MemberNotNull(nameof(_type))]
public override void Update()
{
var val = Property.GetValue(_target);
RaiseAndSetIfChanged(ref _value, val, nameof(Value));
- RaiseAndSetIfChanged(ref _type, _value?.GetType().Name, nameof(Type));
+ RaiseAndSetIfChanged(ref _type, _value?.GetType().Name ?? Property.PropertyType.Name, nameof(Type));
}
}
}
diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ConsoleViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ConsoleViewModel.cs
index 0e0c44ded8..717b49d074 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ConsoleViewModel.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ConsoleViewModel.cs
@@ -15,11 +15,12 @@ namespace Avalonia.Diagnostics.ViewModels
private int _historyIndex = -1;
private string _input;
private bool _isVisible;
- private ScriptState