Browse Source

Fix common warnings (#20311)

pull/20322/head
Julien Lebosquain 2 months ago
committed by GitHub
parent
commit
64b63fa5d2
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      .editorconfig
  2. 1
      samples/Directory.Build.props
  3. 7
      samples/GpuInterop/GpuInterop.csproj
  4. 8
      samples/MiniMvvm/MiniCommand.cs
  5. 6
      samples/MiniMvvm/PropertyChangedExtensions.cs
  6. 4
      samples/TextTestApp/InteractiveLineControl.cs
  7. 14
      samples/TextTestApp/MainWindow.axaml.cs
  8. 3
      src/Android/Avalonia.Android/Avalonia.Android.csproj
  9. 3
      src/Android/Avalonia.Android/ChoreographerTimer.cs
  10. 2
      src/Android/Avalonia.Android/Platform/Storage/AndroidStorageProvider.cs
  11. 8
      src/Avalonia.Base/Controls/NameScope.cs
  12. 1
      src/Avalonia.Base/Media/PolylineGeometry.cs
  13. 2
      src/Avalonia.Base/Media/TextFormatting/TextParagraphProperties.cs
  14. 6
      src/Avalonia.Base/Media/TextPathSegmentEllipsis.cs
  15. 4
      src/Avalonia.Base/Platform/Storage/FilePickerOpenOptions.cs
  16. 2
      src/Avalonia.Base/Platform/Storage/NoopStorageProvider.cs
  17. 7
      src/Avalonia.Base/Platform/Storage/SaveFilePickerResult.cs
  18. 2
      src/Avalonia.Base/Rendering/Composition/CompositionDrawingSurface.cs
  19. 6
      src/Avalonia.Base/Styling/Selector.cs
  20. 17
      src/Avalonia.Base/Threading/DispatcherPriorityAwaitable.cs
  21. 5
      src/Avalonia.Controls/TextBlock.cs
  22. 2
      src/Avalonia.DesignerSupport/Remote/Stubs.cs
  23. 2
      src/Avalonia.Dialogs/ManagedStorageProvider.cs
  24. 2
      src/Avalonia.FreeDesktop/DBusSystemDialog.cs
  25. 2
      src/Avalonia.Native/GpuHandleWrapFeature.cs
  26. 2
      src/Avalonia.Native/StorageProviderImpl.cs
  27. 2
      src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs
  28. 2
      src/Browser/Avalonia.Browser/Storage/BrowserStorageProvider.cs
  29. 4
      src/Markup/Avalonia.Markup.Xaml.Loader/Avalonia.Markup.Xaml.Loader.csproj
  30. 2
      src/Windows/Avalonia.Win32/Win32StorageProvider.cs
  31. 2
      src/iOS/Avalonia.iOS/Storage/IOSStorageProvider.cs
  32. 2
      tests/Avalonia.Base.UnitTests/Input/PointerTestsBase.cs
  33. 2
      tests/Avalonia.Build.Tasks.UnitTest/CompileAvaloniaXamlTaskTest.cs
  34. 2
      tests/Avalonia.Controls.UnitTests/GridSplitterTests.cs
  35. 2
      tests/Avalonia.Controls.UnitTests/Platform/ScreensTests.cs
  36. 16
      tests/Avalonia.Controls.UnitTests/Shapes/ShapeTests.cs
  37. 3
      tests/Avalonia.Controls.UnitTests/ToolTipTests.cs
  38. 4
      tests/Avalonia.Headless.UnitTests/IsolationTests.cs
  39. 6
      tests/Avalonia.IntegrationTests.Appium/Avalonia.IntegrationTests.Appium.csproj
  40. 2
      tests/Avalonia.LeakTests/AvaloniaObjectTests.cs
  41. 16
      tests/Avalonia.LeakTests/ControlTests.cs
  42. 2
      tests/Avalonia.Markup.UnitTests/Data/BindingTests_Delay.cs
  43. 2
      tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs
  44. 2
      tests/Avalonia.RenderTests/CrossTests/Media/ImageScalingTests.cs
  45. 8
      tests/Avalonia.Skia.UnitTests/Media/CustomFontManagerImpl.cs
  46. 8
      tests/Avalonia.UnitTests/HarfBuzzFontManagerImpl.cs
  47. 20
      tests/Avalonia.UnitTests/TestRoot.cs
  48. 2
      tests/Avalonia.UnitTests/ThreadRunHelper.cs
  49. 1
      tests/Directory.Build.props

3
.editorconfig

@ -141,9 +141,6 @@ dotnet_analyzer_diagnostic.category-Performance.severity = none #error - Uncomme
# CS0649: Field 'field' is never assigned to, and will always have its default value 'value' # CS0649: Field 'field' is never assigned to, and will always have its default value 'value'
dotnet_diagnostic.CS0649.severity = error dotnet_diagnostic.CS0649.severity = error
# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1591.severity = suggestion
# CS0162: Remove unreachable code # CS0162: Remove unreachable code
dotnet_diagnostic.CS0162.severity = error dotnet_diagnostic.CS0162.severity = error
# CA1018: Mark attributes with AttributeUsageAttribute # CA1018: Mark attributes with AttributeUsageAttribute

1
samples/Directory.Build.props

@ -4,6 +4,7 @@
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<AvaloniaPreviewerNetCoreToolPath>$(MSBuildThisFileDirectory)..\src\tools\Avalonia.Designer.HostApp\bin\Debug\$(AvsCurrentTargetFramework)\Avalonia.Designer.HostApp.dll</AvaloniaPreviewerNetCoreToolPath> <AvaloniaPreviewerNetCoreToolPath>$(MSBuildThisFileDirectory)..\src\tools\Avalonia.Designer.HostApp\bin\Debug\$(AvsCurrentTargetFramework)\Avalonia.Designer.HostApp.dll</AvaloniaPreviewerNetCoreToolPath>
<EnableNETAnalyzers>false</EnableNETAnalyzers> <EnableNETAnalyzers>false</EnableNETAnalyzers>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<LangVersion>14.0</LangVersion> <LangVersion>14.0</LangVersion>
<NoWarn>$(NoWarn);CS8002</NoWarn> <!-- ignore signing warnings for samples --> <NoWarn>$(NoWarn);CS8002</NoWarn> <!-- ignore signing warnings for samples -->
</PropertyGroup> </PropertyGroup>

7
samples/GpuInterop/GpuInterop.csproj

@ -5,9 +5,14 @@
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework> <TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<UseD3DCompiler>true</UseD3DCompiler> <UseD3DCompiler>true</UseD3DCompiler>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!--
Reference to System.Text.Json is explicitly added to avoid a deprecated version,
we don't care about it not being pruned.
-->
<NoWarn>$(NoWarn);NU1510</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

8
samples/MiniMvvm/MiniCommand.cs

@ -58,10 +58,10 @@ namespace MiniMvvm
{ {
public static MiniCommand Create(Action cb) => new MiniCommand<object>(_ => cb()); public static MiniCommand Create(Action cb) => new MiniCommand<object>(_ => cb());
public static MiniCommand Create<TArg>(Action<TArg> cb) => new MiniCommand<TArg>(cb); public static MiniCommand Create<TArg>(Action<TArg> cb) => new MiniCommand<TArg>(cb);
public static MiniCommand CreateFromTask(Func<Task> cb) => new MiniCommand<object>(_ => cb()); public static MiniCommand CreateFromTask(Func<Task> cb) => new MiniCommand<object?>(_ => cb());
public abstract bool CanExecute(object parameter); public abstract bool CanExecute(object? parameter);
public abstract void Execute(object parameter); public abstract void Execute(object? parameter);
public abstract event EventHandler CanExecuteChanged; public abstract event EventHandler? CanExecuteChanged;
} }
} }

6
samples/MiniMvvm/PropertyChangedExtensions.cs

@ -31,13 +31,13 @@ namespace MiniMvvm
_info = info; _info = info;
_observer = observer; _observer = observer;
_target.PropertyChanged += OnPropertyChanged; _target.PropertyChanged += OnPropertyChanged;
_observer.OnNext((T)_info.GetValue(_target)); _observer.OnNext((T)_info.GetValue(_target)!);
} }
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == _info.Name) if (e.PropertyName == _info.Name)
_observer.OnNext((T)_info.GetValue(_target)); _observer.OnNext((T)_info.GetValue(_target)!);
} }
public void Dispose() public void Dispose()

4
samples/TextTestApp/InteractiveLineControl.cs

@ -233,6 +233,7 @@ namespace TextTestApp
} }
private GenericTextRunProperties? _textRunProperties; private GenericTextRunProperties? _textRunProperties;
public GenericTextRunProperties TextRunProperties public GenericTextRunProperties TextRunProperties
{ {
get get
@ -241,9 +242,6 @@ namespace TextTestApp
} }
set set
{ {
if (value == null)
throw new ArgumentNullException(nameof(value));
_textRunProperties = value; _textRunProperties = value;
SetCurrentValue(FontFamilyProperty, value.Typeface.FontFamily); SetCurrentValue(FontFamilyProperty, value.Typeface.FontFamily);
SetCurrentValue(FontFeaturesProperty, value.FontFeatures); SetCurrentValue(FontFeaturesProperty, value.FontFeatures);

14
samples/TextTestApp/MainWindow.axaml.cs

@ -320,11 +320,17 @@ namespace TextTestApp
private void OnBufferSelectionChanged(object? sender, SelectionChangedEventArgs e) private void OnBufferSelectionChanged(object? sender, SelectionChangedEventArgs e)
{ {
List<Rect> rectangles = new List<Rect>(_buffer.Selection.Count); if (_selectionAdorner is null)
return;
foreach (var row in _buffer.SelectedItems) var rectangles = new List<Rect>(_buffer.Selection.Count);
if (row is Control { Tag: Rect rect })
rectangles.Add(rect); if (_buffer.SelectedItems is { } selectedItems)
{
foreach (var row in selectedItems)
if (row is Control { Tag: Rect rect })
rectangles.Add(rect);
}
_selectionAdorner.Rectangles = rectangles; _selectionAdorner.Rectangles = rectangles;
} }

3
src/Android/Avalonia.Android/Avalonia.Android.csproj

@ -4,6 +4,9 @@
<SupportedOSPlatformVersion>$(AvsMinSupportedAndroidVersion)</SupportedOSPlatformVersion> <SupportedOSPlatformVersion>$(AvsMinSupportedAndroidVersion)</SupportedOSPlatformVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AndroidResgenNamespace>Avalonia.Android.Internal</AndroidResgenNamespace> <AndroidResgenNamespace>Avalonia.Android.Internal</AndroidResgenNamespace>
<!-- Xamarin.AndroidX assemblies are not signed -->
<NoWarn>$(NoWarn);CS8002</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\packages\Avalonia\Avalonia.csproj" /> <ProjectReference Include="..\..\..\packages\Avalonia\Avalonia.csproj" />

3
src/Android/Avalonia.Android/ChoreographerTimer.cs

@ -13,7 +13,6 @@ namespace Avalonia.Android
{ {
internal sealed class ChoreographerTimer : IRenderTimer internal sealed class ChoreographerTimer : IRenderTimer
{ {
private static readonly bool s_supports64Callback = OperatingSystem.IsAndroidVersionAtLeast(29);
private readonly object _lock = new(); private readonly object _lock = new();
private readonly TaskCompletionSource<IntPtr> _choreographer = new(); private readonly TaskCompletionSource<IntPtr> _choreographer = new();
private readonly AutoResetEvent _event = new(false); private readonly AutoResetEvent _event = new(false);
@ -126,7 +125,7 @@ namespace Avalonia.Android
private static unsafe void PostFrameCallback(IntPtr choreographer, IntPtr data) private static unsafe void PostFrameCallback(IntPtr choreographer, IntPtr data)
{ {
// AChoreographer_postFrameCallback is deprecated on 10.0+. // AChoreographer_postFrameCallback is deprecated on 10.0+.
if (s_supports64Callback) if (OperatingSystem.IsAndroidVersionAtLeast(29))
{ {
AChoreographer_postFrameCallback64(choreographer, &FrameCallback64, data); AChoreographer_postFrameCallback64(choreographer, &FrameCallback64, data);
} }

2
src/Android/Avalonia.Android/Platform/Storage/AndroidStorageProvider.cs

@ -202,7 +202,7 @@ internal class AndroidStorageProvider : IStorageProvider
public async Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options) public async Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options)
{ {
var file = await SaveFilePickerAsync(options).ConfigureAwait(false); var file = await SaveFilePickerAsync(options).ConfigureAwait(false);
return new SaveFilePickerResult(file); return new SaveFilePickerResult { File = file };
} }
public async Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(FolderPickerOpenOptions options) public async Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(FolderPickerOpenOptions options)

8
src/Avalonia.Base/Controls/NameScope.cs

@ -14,8 +14,8 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Defines the NameScope attached property. /// Defines the NameScope attached property.
/// </summary> /// </summary>
public static readonly AttachedProperty<INameScope> NameScopeProperty = public static readonly AttachedProperty<INameScope?> NameScopeProperty =
AvaloniaProperty.RegisterAttached<NameScope, StyledElement, INameScope>("NameScope"); AvaloniaProperty.RegisterAttached<NameScope, StyledElement, INameScope?>("NameScope");
/// <inheritdoc/> /// <inheritdoc/>
public bool IsCompleted { get; private set; } public bool IsCompleted { get; private set; }
@ -30,7 +30,7 @@ namespace Avalonia.Controls
/// </summary> /// </summary>
/// <param name="styled">The styled element.</param> /// <param name="styled">The styled element.</param>
/// <returns>The value of the NameScope attached property.</returns> /// <returns>The value of the NameScope attached property.</returns>
public static INameScope GetNameScope(StyledElement styled) public static INameScope? GetNameScope(StyledElement styled)
{ {
_ = styled ?? throw new ArgumentNullException(nameof(styled)); _ = styled ?? throw new ArgumentNullException(nameof(styled));
@ -42,7 +42,7 @@ namespace Avalonia.Controls
/// </summary> /// </summary>
/// <param name="styled">The styled element.</param> /// <param name="styled">The styled element.</param>
/// <param name="value">The value to set.</param> /// <param name="value">The value to set.</param>
public static void SetNameScope(StyledElement styled, INameScope value) public static void SetNameScope(StyledElement styled, INameScope? value)
{ {
_ = styled ?? throw new ArgumentNullException(nameof(styled)); _ = styled ?? throw new ArgumentNullException(nameof(styled));

1
src/Avalonia.Base/Media/PolylineGeometry.cs

@ -44,7 +44,6 @@ namespace Avalonia.Media
_fillRule = FillRule.EvenOdd; _fillRule = FillRule.EvenOdd;
} }
/// <summary>
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PolylineGeometry"/> class. /// Initializes a new instance of the <see cref="PolylineGeometry"/> class.
/// </summary> /// </summary>

2
src/Avalonia.Base/Media/TextFormatting/TextParagraphProperties.cs

@ -53,7 +53,7 @@
/// <remarks> /// <remarks>
/// If not null, text decorations to apply to all runs in the line. This is in addition /// If not null, text decorations to apply to all runs in the line. This is in addition
/// to any text decorations specified by the TextRunProperties for individual text runs. /// to any text decorations specified by the TextRunProperties for individual text runs.
/// </summary> /// </remarks>
public virtual TextDecorationCollection? TextDecorations => null; public virtual TextDecorationCollection? TextDecorations => null;
/// <summary> /// <summary>

6
src/Avalonia.Base/Media/TextPathSegmentEllipsis.cs

@ -415,12 +415,6 @@ namespace Avalonia.Media
return false; return false;
} }
/// <summary>
/// Finds the index of the text run and the offset within that run corresponding to the specified character
/// index.
/// </summary>
/// <remarks>If the specified character index does not fall within any run, the method returns
/// <summary> /// <summary>
/// Calculates the total width of a specified segment within a sequence of text runs. /// Calculates the total width of a specified segment within a sequence of text runs.
/// </summary> /// </summary>

4
src/Avalonia.Base/Platform/Storage/FilePickerOpenOptions.cs

@ -11,8 +11,8 @@ public class FilePickerOpenOptions : PickerOptions
/// Gets or sets the file type that should be preselected when the dialog is opened. /// Gets or sets the file type that should be preselected when the dialog is opened.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This value should reference one of the items in <see cref="FileTypeChoices"/>. /// This value should reference one of the items in <see cref="FileTypeFilter"/>.
/// If not set, the first file type in <see cref="FileTypeChoices"/> may be selected by default. /// If not set, the first file type in <see cref="FileTypeFilter"/> may be selected by default.
/// </remarks> /// </remarks>
public FilePickerFileType? SuggestedFileType { get; set; } public FilePickerFileType? SuggestedFileType { get; set; }

2
src/Avalonia.Base/Platform/Storage/NoopStorageProvider.cs

@ -21,7 +21,7 @@ internal class NoopStorageProvider : BclStorageProvider
public override Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options) public override Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options)
{ {
return Task.FromResult(new SaveFilePickerResult(null)); return Task.FromResult(new SaveFilePickerResult());
} }
public override bool CanPickFolder => false; public override bool CanPickFolder => false;

7
src/Avalonia.Base/Platform/Storage/SaveFilePickerResult.cs

@ -3,13 +3,8 @@ namespace Avalonia.Platform.Storage;
/// <summary> /// <summary>
/// Extended result of the <see cref="IStorageProvider.SaveFilePickerWithResultAsync(FilePickerSaveOptions)"/> operation. /// Extended result of the <see cref="IStorageProvider.SaveFilePickerWithResultAsync(FilePickerSaveOptions)"/> operation.
/// </summary> /// </summary>
public readonly struct SaveFilePickerResult public readonly record struct SaveFilePickerResult
{ {
internal SaveFilePickerResult(IStorageFile? file)
{
File = file;
}
/// <summary> /// <summary>
/// Saved <see cref="IStorageFile"/> or null if user canceled the dialog. /// Saved <see cref="IStorageFile"/> or null if user canceled the dialog.
/// </summary> /// </summary>

2
src/Avalonia.Base/Rendering/Composition/CompositionDrawingSurface.cs

@ -47,7 +47,9 @@ public sealed class CompositionDrawingSurface : CompositionSurface, IDisposable
/// </summary> /// </summary>
/// <param name="image">GPU image with new surface contents</param> /// <param name="image">GPU image with new surface contents</param>
/// <param name="waitForSemaphore">The semaphore to wait for before accessing the image</param> /// <param name="waitForSemaphore">The semaphore to wait for before accessing the image</param>
/// <param name="waitForValue">The value to wait for before accessing the image</param>
/// <param name="signalSemaphore">The semaphore to signal after accessing the image</param> /// <param name="signalSemaphore">The semaphore to signal after accessing the image</param>
/// <param name="signalValue">The value to signal after accessing the image</param>
/// <returns>A task that completes when update operation is completed and user code is free to destroy or dispose the image</returns> /// <returns>A task that completes when update operation is completed and user code is free to destroy or dispose the image</returns>
public Task UpdateWithTimelineSemaphoresAsync(ICompositionImportedGpuImage image, public Task UpdateWithTimelineSemaphoresAsync(ICompositionImportedGpuImage image,
ICompositionImportedGpuSemaphore waitForSemaphore, ulong waitForValue, ICompositionImportedGpuSemaphore waitForSemaphore, ulong waitForValue,

6
src/Avalonia.Base/Styling/Selector.cs

@ -76,7 +76,11 @@ namespace Avalonia.Styling
/// <param name="owner">The owner style.</param> /// <param name="owner">The owner style.</param>
public abstract string ToString(Style? owner); public abstract string ToString(Style? owner);
/// <inheritdoc cref="ToString(Style?)"/> /// <summary>
/// Gets a string representing the selector, with the nesting separator (`^`) replaced with
/// the parent selector.
/// </summary>
/// <param name="owner">The owner style.</param>
/// <param name="hasNext">Whether there is a selector that comes after this one.</param> /// <param name="hasNext">Whether there is a selector that comes after this one.</param>
internal virtual string ToString(Style? owner, bool hasNext) => ToString(owner); internal virtual string ToString(Style? owner, bool hasNext) => ToString(owner);

17
src/Avalonia.Base/Threading/DispatcherPriorityAwaitable.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -8,6 +9,10 @@ namespace Avalonia.Threading;
/// <summary> /// <summary>
/// A simple awaitable type that will return a DispatcherPriorityAwaiter. /// A simple awaitable type that will return a DispatcherPriorityAwaiter.
/// </summary> /// </summary>
[UnconditionalSuppressMessage(
"Performance",
"CA1815:Override equals and operator equals on value types",
Justification = "This struct is not supposed to be used directly and should not be compared.")]
public struct DispatcherPriorityAwaitable public struct DispatcherPriorityAwaitable
{ {
private readonly Dispatcher _dispatcher; private readonly Dispatcher _dispatcher;
@ -30,6 +35,10 @@ public struct DispatcherPriorityAwaitable
/// <remarks> /// <remarks>
/// This is returned from DispatcherPriorityAwaitable.GetAwaiter() /// This is returned from DispatcherPriorityAwaitable.GetAwaiter()
/// </remarks> /// </remarks>
[UnconditionalSuppressMessage(
"Performance",
"CA1815:Override equals and operator equals on value types",
Justification = "This struct is not supposed to be used directly and should not be compared.")]
public struct DispatcherPriorityAwaiter : INotifyCompletion public struct DispatcherPriorityAwaiter : INotifyCompletion
{ {
private readonly Dispatcher _dispatcher; private readonly Dispatcher _dispatcher;
@ -72,6 +81,10 @@ public struct DispatcherPriorityAwaiter : INotifyCompletion
/// <summary> /// <summary>
/// A simple awaitable type that will return a DispatcherPriorityAwaiter&lt;T&gt;. /// A simple awaitable type that will return a DispatcherPriorityAwaiter&lt;T&gt;.
/// </summary> /// </summary>
[UnconditionalSuppressMessage(
"Performance",
"CA1815:Override equals and operator equals on value types",
Justification = "This struct is not supposed to be used directly and should not be compared.")]
public struct DispatcherPriorityAwaitable<T> public struct DispatcherPriorityAwaitable<T>
{ {
private readonly Dispatcher _dispatcher; private readonly Dispatcher _dispatcher;
@ -94,6 +107,10 @@ public struct DispatcherPriorityAwaitable<T>
/// <remarks> /// <remarks>
/// This is returned from DispatcherPriorityAwaitable&lt;T&gt;.GetAwaiter() /// This is returned from DispatcherPriorityAwaitable&lt;T&gt;.GetAwaiter()
/// </remarks> /// </remarks>
[UnconditionalSuppressMessage(
"Performance",
"CA1815:Override equals and operator equals on value types",
Justification = "This struct is not supposed to be used directly and should not be compared.")]
public struct DispatcherPriorityAwaiter<T> : INotifyCompletion public struct DispatcherPriorityAwaiter<T> : INotifyCompletion
{ {
private readonly Dispatcher _dispatcher; private readonly Dispatcher _dispatcher;

5
src/Avalonia.Controls/TextBlock.cs

@ -97,11 +97,6 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Defines the <see cref="LetterSpacing"/> property. /// Defines the <see cref="LetterSpacing"/> property.
/// </summary> /// </summary>
/// <remarks>
/// This property uses <see cref="AvaloniaProperty.AddOwner{TOwner}(AvaloniaProperty)"/> to share the same
/// definition as <see cref="TextElement.LetterSpacingProperty"/>, ensuring consistent behavior across text
/// elements and templated controls.
/// </remarks>
public static readonly StyledProperty<double> LetterSpacingProperty = public static readonly StyledProperty<double> LetterSpacingProperty =
TextElement.LetterSpacingProperty.AddOwner<TextBlock>(); TextElement.LetterSpacingProperty.AddOwner<TextBlock>();

2
src/Avalonia.DesignerSupport/Remote/Stubs.cs

@ -309,7 +309,7 @@ namespace Avalonia.DesignerSupport.Remote
public override Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options) public override Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options)
{ {
return Task.FromResult<SaveFilePickerResult>(new SaveFilePickerResult(null)); return Task.FromResult(new SaveFilePickerResult());
} }
public override bool CanPickFolder => false; public override bool CanPickFolder => false;

2
src/Avalonia.Dialogs/ManagedStorageProvider.cs

@ -56,7 +56,7 @@ internal class ManagedStorageProvider : BclStorageProvider
options.FileTypeChoices[index] : options.FileTypeChoices[index] :
null; null;
return new SaveFilePickerResult(file) { SelectedFileType = filterType }; return new SaveFilePickerResult { File = file, SelectedFileType = filterType };
} }
public override async Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(FolderPickerOpenOptions options) public override async Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(FolderPickerOpenOptions options)

2
src/Avalonia.FreeDesktop/DBusSystemDialog.cs

@ -102,7 +102,7 @@ namespace Avalonia.FreeDesktop
public override async Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options) public override async Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options)
{ {
var (file, selectedType) = await SaveFilePickerCoreAsync(options).ConfigureAwait(false); var (file, selectedType) = await SaveFilePickerCoreAsync(options).ConfigureAwait(false);
return new SaveFilePickerResult(file) { SelectedFileType = selectedType }; return new SaveFilePickerResult { File = file, SelectedFileType = selectedType };
} }
private async Task<(IStorageFile? file, FilePickerFileType? selectedType)> SaveFilePickerCoreAsync( private async Task<(IStorageFile? file, FilePickerFileType? selectedType)> SaveFilePickerCoreAsync(

2
src/Avalonia.Native/GpuHandleWrapFeature.cs

@ -1,3 +1,5 @@
#nullable enable
using System; using System;
using Avalonia.Native.Interop; using Avalonia.Native.Interop;
using Avalonia.Platform; using Avalonia.Platform;

2
src/Avalonia.Native/StorageProviderImpl.cs

@ -30,7 +30,7 @@ internal sealed class StorageProviderImpl(TopLevelImpl topLevel, StorageProvider
public async Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options) public async Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options)
{ {
var (file, selectedType) = await native.SaveFileDialog(topLevel, options).ConfigureAwait(false); var (file, selectedType) = await native.SaveFileDialog(topLevel, options).ConfigureAwait(false);
return new SaveFilePickerResult(file) { SelectedFileType = selectedType }; return new SaveFilePickerResult { File = file, SelectedFileType = selectedType };
} }
public Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(FolderPickerOpenOptions options) public Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(FolderPickerOpenOptions options)

2
src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs

@ -86,7 +86,7 @@ namespace Avalonia.X11.NativeDialogs
? new BclStorageFile(new FileInfo(path)) ? new BclStorageFile(new FileInfo(path))
: null; : null;
return new SaveFilePickerResult(file) { SelectedFileType = selectedFilter }; return new SaveFilePickerResult { File = file, SelectedFileType = selectedFilter };
}); });
} }

2
src/Browser/Avalonia.Browser/Storage/BrowserStorageProvider.cs

@ -93,7 +93,7 @@ internal class BrowserStorageProvider : IStorageProvider
public async Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options) public async Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options)
{ {
var file = await SaveFilePickerAsync(options).ConfigureAwait(false); var file = await SaveFilePickerAsync(options).ConfigureAwait(false);
return new SaveFilePickerResult(file); return new SaveFilePickerResult { File = file };
} }
public async Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(FolderPickerOpenOptions options) public async Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(FolderPickerOpenOptions options)

4
src/Markup/Avalonia.Markup.Xaml.Loader/Avalonia.Markup.Xaml.Loader.csproj

@ -11,10 +11,6 @@
<ProjectReference Include="..\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj" /> <ProjectReference Include="..\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Include="../../Avalonia.Base/Diagnostics/TrimmingMessages.cs" Link="Diagnostics/AvaloniaTrimmingMessages.cs" />
</ItemGroup>
<Import Project="IncludeXamlIlSre.props" /> <Import Project="IncludeXamlIlSre.props" />
<Import Project="..\..\..\build\DevAnalyzers.props" /> <Import Project="..\..\..\build\DevAnalyzers.props" />
<Import Project="..\..\..\build\TrimmingEnable.props" /> <Import Project="..\..\..\build\TrimmingEnable.props" />

2
src/Windows/Avalonia.Win32/Win32StorageProvider.cs

@ -79,7 +79,7 @@ namespace Avalonia.Win32
options.FileTypeChoices[index - 1] : options.FileTypeChoices[index - 1] :
null; null;
return new SaveFilePickerResult(file) { SelectedFileType = selectedFileType }; return new SaveFilePickerResult { File = file, SelectedFileType = selectedFileType };
} }
private unsafe Task<(IReadOnlyList<TStorageItem> items, int typeIndex)> ShowFilePicker<TStorageItem>( private unsafe Task<(IReadOnlyList<TStorageItem> items, int typeIndex)> ShowFilePicker<TStorageItem>(

2
src/iOS/Avalonia.iOS/Storage/IOSStorageProvider.cs

@ -232,7 +232,7 @@ internal class IOSStorageProvider : IStorageProvider
public async Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options) public async Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options)
{ {
var file = await SaveFilePickerAsync(options).ConfigureAwait(false); var file = await SaveFilePickerAsync(options).ConfigureAwait(false);
return new SaveFilePickerResult(file); return new SaveFilePickerResult { File = file };
} }
public async Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(FolderPickerOpenOptions options) public async Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(FolderPickerOpenOptions options)

2
tests/Avalonia.Base.UnitTests/Input/PointerTestsBase.cs

@ -49,7 +49,7 @@ public abstract class PointerTestsBase : ScopedTestBase
impl.DefaultValue = DefaultValue.Mock; impl.DefaultValue = DefaultValue.Mock;
impl.SetupAllProperties(); impl.SetupAllProperties();
impl.SetupGet(r => r.RenderScaling).Returns(1); impl.SetupGet(r => r.RenderScaling).Returns(1);
impl.Setup(r => r.TryGetFeature(It.IsAny<Type>())).Returns(null); impl.Setup(r => r.TryGetFeature(It.IsAny<Type>())).Returns((object?)null);
impl.Setup(r => r.Compositor).Returns(RendererMocks.CreateDummyCompositor()); impl.Setup(r => r.Compositor).Returns(RendererMocks.CreateDummyCompositor());
impl.Setup(r => r.PointToScreen(It.IsAny<Point>())).Returns<Point>(p => new PixelPoint((int)p.X, (int)p.Y)); impl.Setup(r => r.PointToScreen(It.IsAny<Point>())).Returns<Point>(p => new PixelPoint((int)p.X, (int)p.Y));
impl.Setup(r => r.PointToClient(It.IsAny<PixelPoint>())).Returns<PixelPoint>(p => new Point(p.X, p.Y)); impl.Setup(r => r.PointToClient(It.IsAny<PixelPoint>())).Returns<PixelPoint>(p => new Point(p.X, p.Y));

2
tests/Avalonia.Build.Tasks.UnitTest/CompileAvaloniaXamlTaskTest.cs

@ -14,7 +14,7 @@ public class CompileAvaloniaXamlTaskTest
public void Does_Not_Fail_When_Codebehind_Contains_DllImport() public void Does_Not_Fail_When_Codebehind_Contains_DllImport()
{ {
using var engine = UnitTestBuildEngine.Start(); using var engine = UnitTestBuildEngine.Start();
var basePath = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), "Assets"); var basePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
var assembly = new TaskItem(Path.Combine(basePath, "PInvoke.dll")); var assembly = new TaskItem(Path.Combine(basePath, "PInvoke.dll"));
assembly.SetMetadata(CompileAvaloniaXamlTask.AvaloniaCompileOutputMetadataName, Path.Combine(basePath, "Avalonia", Path.GetFileName(assembly.ItemSpec))); assembly.SetMetadata(CompileAvaloniaXamlTask.AvaloniaCompileOutputMetadataName, Path.Combine(basePath, "Avalonia", Path.GetFileName(assembly.ItemSpec)));
var references = File.ReadAllLines(Path.Combine(basePath, "PInvoke.dll.refs")).Select(p => new TaskItem(p)).ToArray(); var references = File.ReadAllLines(Path.Combine(basePath, "PInvoke.dll.refs")).Select(p => new TaskItem(p)).ToArray();

2
tests/Avalonia.Controls.UnitTests/GridSplitterTests.cs

@ -1,3 +1,5 @@
#nullable enable
using System.Collections.Generic; using System.Collections.Generic;
using Avalonia.Controls.Presenters; using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;

2
tests/Avalonia.Controls.UnitTests/Platform/ScreensTests.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Threading; using Avalonia.Threading;
@ -102,6 +103,7 @@ public class ScreensTests : ScopedTestBase
} }
[Fact] [Fact]
[UnconditionalSuppressMessage("Usage", "xUnit1031:Do not use blocking task operations in test method", Justification = "Explicit threading test")]
public void Should_Raise_Event_When_Screen_Changed_From_Another_Thread() public void Should_Raise_Event_When_Screen_Changed_From_Another_Thread()
{ {
using var _ = UnitTestApplication.Start(TestServices.MockThreadingInterface); using var _ = UnitTestApplication.Start(TestServices.MockThreadingInterface);

16
tests/Avalonia.Controls.UnitTests/Shapes/ShapeTests.cs

@ -1,3 +1,5 @@
#nullable enable
using Avalonia.Collections; using Avalonia.Collections;
using Avalonia.Controls.Shapes; using Avalonia.Controls.Shapes;
using Avalonia.Media; using Avalonia.Media;
@ -22,7 +24,7 @@ public class ShapeTests : ScopedTestBase
}); });
Assert.NotNull(pen); Assert.NotNull(pen);
Assert.Equal(10, pen!.MiterLimit); Assert.Equal(10, pen.MiterLimit);
} }
[Fact] [Fact]
@ -40,7 +42,7 @@ public class ShapeTests : ScopedTestBase
var pen = RenderAndGetPen(shape); var pen = RenderAndGetPen(shape);
Assert.NotNull(pen); Assert.NotNull(pen);
Assert.Equal(2, pen!.MiterLimit); Assert.Equal(2, pen.MiterLimit);
} }
[Fact] [Fact]
@ -54,7 +56,7 @@ public class ShapeTests : ScopedTestBase
}); });
Assert.NotNull(pen); Assert.NotNull(pen);
Assert.Equal(6, pen!.Thickness); Assert.Equal(6, pen.Thickness);
} }
[Fact] [Fact]
@ -70,7 +72,7 @@ public class ShapeTests : ScopedTestBase
}); });
Assert.NotNull(pen); Assert.NotNull(pen);
Assert.Equal(PenLineCap.Round, pen!.LineCap); Assert.Equal(PenLineCap.Round, pen.LineCap);
Assert.Equal(PenLineJoin.Bevel, pen.LineJoin); Assert.Equal(PenLineJoin.Bevel, pen.LineJoin);
} }
@ -87,8 +89,8 @@ public class ShapeTests : ScopedTestBase
}); });
Assert.NotNull(pen); Assert.NotNull(pen);
Assert.NotNull(pen!.DashStyle); Assert.NotNull(pen.DashStyle);
Assert.Equal(3, pen.DashStyle!.Dashes.Count); Assert.Equal(3, pen.DashStyle!.Dashes!.Count);
Assert.Equal(1, pen.DashStyle.Dashes[0]); Assert.Equal(1, pen.DashStyle.Dashes[0]);
Assert.Equal(2, pen.DashStyle.Dashes[1]); Assert.Equal(2, pen.DashStyle.Dashes[1]);
Assert.Equal(3, pen.DashStyle.Dashes[2]); Assert.Equal(3, pen.DashStyle.Dashes[2]);
@ -117,7 +119,7 @@ public class ShapeTests : ScopedTestBase
private class TestShape : Shape private class TestShape : Shape
{ {
protected override Geometry? CreateDefiningGeometry() => protected override Geometry CreateDefiningGeometry() =>
new RectangleGeometry(new Rect(0, 0, 20, 20)); new RectangleGeometry(new Rect(0, 0, 20, 20));
} }

3
tests/Avalonia.Controls.UnitTests/ToolTipTests.cs

@ -42,9 +42,10 @@ namespace Avalonia.Controls.UnitTests
})); }));
} }
public void Dispose() public override void Dispose()
{ {
_toolTipOpenSubscription.Dispose(); _toolTipOpenSubscription.Dispose();
base.Dispose();
} }
protected override TestServices ConfigureServices(TestServices baseServices) => protected override TestServices ConfigureServices(TestServices baseServices) =>

4
tests/Avalonia.Headless.UnitTests/IsolationTests.cs

@ -15,6 +15,10 @@ public class IsolationTests
#elif XUNIT #elif XUNIT
[AvaloniaTheory] [AvaloniaTheory]
[InlineData(1), InlineData(2), InlineData(3)] [InlineData(1), InlineData(2), InlineData(3)]
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(
"Usage",
"xUnit1026:Theory methods should use all of their parameters",
Justification = "Used to run the test several times with the proper isolation level")]
#endif #endif
public void Application_Instance_Should_Match_Isolation_Level(int runIndex) public void Application_Instance_Should_Match_Isolation_Level(int runIndex)
{ {

6
tests/Avalonia.IntegrationTests.Appium/Avalonia.IntegrationTests.Appium.csproj

@ -7,6 +7,12 @@
<IsRunningAppium2 Condition="'$(IsRunningAppium2)' == ''">false</IsRunningAppium2> <IsRunningAppium2 Condition="'$(IsRunningAppium2)' == ''">false</IsRunningAppium2>
<DefineConstants Condition="'$(IsRunningAppium2)' == 'false'">$(DefineConstants);APPIUM1</DefineConstants> <DefineConstants Condition="'$(IsRunningAppium2)' == 'false'">$(DefineConstants);APPIUM1</DefineConstants>
<DefineConstants Condition="'$(IsRunningAppium2)' == 'true'">$(DefineConstants);APPIUM2</DefineConstants> <DefineConstants Condition="'$(IsRunningAppium2)' == 'true'">$(DefineConstants);APPIUM2</DefineConstants>
<!--
References to System.Net.Http and System.Text.RegularExpressions are explicitly added to
avoid deprecated versions, we don't care about them not being pruned.
-->
<NoWarn>$(NoWarn);NU1510</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

2
tests/Avalonia.LeakTests/AvaloniaObjectTests.cs

@ -54,7 +54,7 @@ namespace Avalonia.LeakTests
Action completeSource = () => Action completeSource = () =>
{ {
((ISubject<string>)weakSource.Target).OnCompleted(); ((ISubject<string>)weakSource.Target!).OnCompleted();
}; };
completeSource(); completeSource();

16
tests/Avalonia.LeakTests/ControlTests.cs

@ -294,7 +294,7 @@ namespace Avalonia.LeakTests
{ {
new FuncTreeDataTemplate<Node>( new FuncTreeDataTemplate<Node>(
(x, _) => new TextBlock { Text = x.Name }, (x, _) => new TextBlock { Text = x.Name },
x => x.Children) x => x.Children ?? [])
}, },
ItemsSource = nodes ItemsSource = nodes
} }
@ -409,7 +409,7 @@ namespace Avalonia.LeakTests
screens.Setup(x => x.ScreenFromWindow(It.IsAny<IWindowBaseImpl>())).Returns(screen1.Object); screens.Setup(x => x.ScreenFromWindow(It.IsAny<IWindowBaseImpl>())).Returns(screen1.Object);
var impl = new Mock<IWindowImpl>(); var impl = new Mock<IWindowImpl>();
impl.Setup(r => r.TryGetFeature(It.IsAny<Type>())).Returns(null); impl.Setup(r => r.TryGetFeature(It.IsAny<Type>())).Returns((object?)null);
impl.SetupGet(x => x.RenderScaling).Returns(1); impl.SetupGet(x => x.RenderScaling).Returns(1);
impl.SetupProperty(x => x.Closed); impl.SetupProperty(x => x.Closed);
impl.Setup(x => x.Compositor).Returns(RendererMocks.CreateDummyCompositor()); impl.Setup(x => x.Compositor).Returns(RendererMocks.CreateDummyCompositor());
@ -516,7 +516,7 @@ namespace Avalonia.LeakTests
Assert.True(weakMenuItem2.IsAlive); Assert.True(weakMenuItem2.IsAlive);
Assert.True(weakContextMenu.IsAlive); Assert.True(weakContextMenu.IsAlive);
Mock.Get(window.PlatformImpl).Invocations.Clear(); Mock.Get(window.PlatformImpl!).Invocations.Clear();
CollectGarbage(); CollectGarbage();
Assert.False(weakMenuItem1.IsAlive); Assert.False(weakMenuItem1.IsAlive);
@ -605,7 +605,7 @@ namespace Avalonia.LeakTests
Assert.True(weakMenuItem4.IsAlive); Assert.True(weakMenuItem4.IsAlive);
Assert.True(weakContextMenu2.IsAlive); Assert.True(weakContextMenu2.IsAlive);
Mock.Get(window.PlatformImpl).Invocations.Clear(); Mock.Get(window.PlatformImpl!).Invocations.Clear();
CollectGarbage(); CollectGarbage();
Assert.False(weakMenuItem1.IsAlive); Assert.False(weakMenuItem1.IsAlive);
@ -930,7 +930,7 @@ namespace Avalonia.LeakTests
window.Content = null; window.Content = null;
// Mock keep reference on a Popup via InvocationsCollection. So let's clear it before. // Mock keep reference on a Popup via InvocationsCollection. So let's clear it before.
Mock.Get(window.PlatformImpl).Invocations.Clear(); Mock.Get(window.PlatformImpl!).Invocations.Clear();
return (new WeakReference(toolTip), new WeakReference(textBlock)); return (new WeakReference(toolTip), new WeakReference(textBlock));
} }
@ -984,7 +984,7 @@ namespace Avalonia.LeakTests
window.Content = null; window.Content = null;
// Mock keep reference on a Popup via InvocationsCollection. So let's clear it before. // Mock keep reference on a Popup via InvocationsCollection. So let's clear it before.
Mock.Get(window.PlatformImpl).Invocations.Clear(); Mock.Get(window.PlatformImpl!).Invocations.Clear();
return (new WeakReference(flyout), new WeakReference(textBlock)); return (new WeakReference(flyout), new WeakReference(textBlock));
} }
@ -1093,8 +1093,8 @@ namespace Avalonia.LeakTests
private class Node private class Node
{ {
public string Name { get; set; } public string? Name { get; set; }
public IEnumerable<Node> Children { get; set; } public IEnumerable<Node>? Children { get; set; }
} }
} }

2
tests/Avalonia.Markup.UnitTests/Data/BindingTests_Delay.cs

@ -36,7 +36,7 @@ public class BindingTests_Delay : ScopedTestBase, IDisposable
Assert.Equal(_source.Foo, _target.Text); Assert.Equal(_source.Foo, _target.Text);
} }
public void Dispose() public override void Dispose()
{ {
_app.Dispose(); _app.Dispose();
base.Dispose(); base.Dispose();

2
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs

@ -2520,7 +2520,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
public class NestedGeneric<T> public class NestedGeneric<T>
{ {
public T Value { get; set; } public T? Value { get; set; }
} }
} }

2
tests/Avalonia.RenderTests/CrossTests/Media/ImageScalingTests.cs

@ -1,3 +1,5 @@
#nullable enable
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Avalonia.Media.Imaging; using Avalonia.Media.Imaging;

8
tests/Avalonia.Skia.UnitTests/Media/CustomFontManagerImpl.cs

@ -1,4 +1,6 @@
using System; #nullable enable
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
@ -96,7 +98,7 @@ namespace Avalonia.Skia.UnitTests.Media
} }
public bool TryCreateGlyphTypeface(string familyName, FontStyle style, FontWeight weight, public bool TryCreateGlyphTypeface(string familyName, FontStyle style, FontWeight weight,
FontStretch stretch, [NotNullWhen(true)] out IGlyphTypeface glyphTypeface) FontStretch stretch, [NotNullWhen(true)] out IGlyphTypeface? glyphTypeface)
{ {
if (SystemFonts.TryGetGlyphTypeface(familyName, style, weight, stretch, out glyphTypeface)) if (SystemFonts.TryGetGlyphTypeface(familyName, style, weight, stretch, out glyphTypeface))
{ {
@ -111,7 +113,7 @@ namespace Avalonia.Skia.UnitTests.Media
return true; return true;
} }
public bool TryCreateGlyphTypeface(Stream stream, FontSimulations fontSimulations, [NotNullWhen(true)] out IGlyphTypeface glyphTypeface) public bool TryCreateGlyphTypeface(Stream stream, FontSimulations fontSimulations, [NotNullWhen(true)] out IGlyphTypeface? glyphTypeface)
{ {
var skTypeface = SKTypeface.FromStream(stream); var skTypeface = SKTypeface.FromStream(stream);

8
tests/Avalonia.UnitTests/HarfBuzzFontManagerImpl.cs

@ -1,4 +1,6 @@
using System; #nullable enable
using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@ -33,7 +35,7 @@ namespace Avalonia.UnitTests
string[] IFontManagerImpl.GetInstalledFontFamilyNames(bool checkForUpdates) string[] IFontManagerImpl.GetInstalledFontFamilyNames(bool checkForUpdates)
{ {
return _customTypefaces.Select(x => x.FontFamily!.Name).ToArray(); return _customTypefaces.Select(x => x.FontFamily.Name).ToArray();
} }
public bool TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fontWeight, public bool TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fontWeight,
@ -66,7 +68,7 @@ namespace Avalonia.UnitTests
} }
public bool TryCreateGlyphTypeface(string familyName, FontStyle style, FontWeight weight, public bool TryCreateGlyphTypeface(string familyName, FontStyle style, FontWeight weight,
FontStretch stretch, [NotNullWhen(true)] out IGlyphTypeface glyphTypeface) FontStretch stretch, [NotNullWhen(true)] out IGlyphTypeface? glyphTypeface)
{ {
glyphTypeface = null; glyphTypeface = null;

20
tests/Avalonia.UnitTests/TestRoot.cs

@ -1,3 +1,5 @@
#nullable enable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Avalonia.Controls; using Avalonia.Controls;
@ -28,17 +30,17 @@ namespace Avalonia.UnitTests
class NullHitTester : IHitTester class NullHitTester : IHitTester
{ {
public IEnumerable<Visual> HitTest(Point p, Visual root, Func<Visual, bool> filter) => Array.Empty<Visual>(); public IEnumerable<Visual> HitTest(Point p, Visual root, Func<Visual, bool>? filter) => Array.Empty<Visual>();
public Visual HitTestFirst(Point p, Visual root, Func<Visual, bool> filter) => null; public Visual? HitTestFirst(Point p, Visual root, Func<Visual, bool>? filter) => null;
} }
public TestRoot(Control child) public TestRoot(Control? child)
: this(false, child) : this(false, child)
{ {
} }
public TestRoot(bool useGlobalStyles, Control child) public TestRoot(bool useGlobalStyles, Control? child)
: this() : this()
{ {
if (useGlobalStyles) if (useGlobalStyles)
@ -63,17 +65,17 @@ namespace Avalonia.UnitTests
IRenderer IRenderRoot.Renderer => Renderer; IRenderer IRenderRoot.Renderer => Renderer;
IHitTester IRenderRoot.HitTester => HitTester; IHitTester IRenderRoot.HitTester => HitTester;
public IKeyboardNavigationHandler KeyboardNavigationHandler => null; public IKeyboardNavigationHandler? KeyboardNavigationHandler => null;
public IFocusManager FocusManager => _focusManager ??= new FocusManager(this); public IFocusManager FocusManager => _focusManager ??= new FocusManager(this);
public IPlatformSettings PlatformSettings => AvaloniaLocator.Current.GetService<IPlatformSettings>(); public IPlatformSettings? PlatformSettings => AvaloniaLocator.Current.GetService<IPlatformSettings>();
public IInputElement PointerOverElement { get; set; } public IInputElement? PointerOverElement { get; set; }
public bool ShowAccessKeys { get; set; } public bool ShowAccessKeys { get; set; }
public IStyleHost StylingParent { get; set; } public IStyleHost? StylingParent { get; set; }
IStyleHost IStyleHost.StylingParent => StylingParent; IStyleHost? IStyleHost.StylingParent => StylingParent;
public IRenderTarget CreateRenderTarget() public IRenderTarget CreateRenderTarget()
{ {

2
tests/Avalonia.UnitTests/ThreadRunHelper.cs

@ -1,3 +1,5 @@
#nullable enable
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

1
tests/Directory.Build.props

@ -2,5 +2,6 @@
<Import Project="..\Directory.Build.props" /> <Import Project="..\Directory.Build.props" />
<PropertyGroup> <PropertyGroup>
<EnableNETAnalyzers>false</EnableNETAnalyzers> <EnableNETAnalyzers>false</EnableNETAnalyzers>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

Loading…
Cancel
Save