diff --git a/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs b/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs
index 83db67fcee..87fd47df25 100644
--- a/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs
+++ b/src/Android/Avalonia.AndroidTestApplication/Resources/Resource.Designer.cs
@@ -14,7 +14,7 @@ namespace Avalonia.AndroidTestApplication
{
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "12.1.99.62")]
public partial class Resource
{
diff --git a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj
index 7884f13ddb..e864ea2007 100644
--- a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj
+++ b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj
@@ -6,7 +6,7 @@
tools
$(DefineConstants);BUILDTASK;XAMLX_CECIL_INTERNAL;XAMLX_INTERNAL
true
- NU1605
+ NU1605;CS8632
diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs
index 27b28f35fc..4416437479 100644
--- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs
+++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs
@@ -86,14 +86,15 @@ namespace Avalonia.Diagnostics.ViewModels
public void SelectControl(IControl control)
{
var node = default(TreeNode);
+ IControl? c = control;
- while (node == null && control != null)
+ while (node == null && c != null)
{
- node = FindNode(control);
+ node = FindNode(c);
if (node == null)
{
- control = control.GetVisualParent();
+ c = c.GetVisualParent();
}
}
diff --git a/src/Avalonia.Input/AccessKeyHandler.cs b/src/Avalonia.Input/AccessKeyHandler.cs
index a3330b65ae..60175ae588 100644
--- a/src/Avalonia.Input/AccessKeyHandler.cs
+++ b/src/Avalonia.Input/AccessKeyHandler.cs
@@ -188,7 +188,7 @@ namespace Avalonia.Input
// If the menu is open, only match controls in the menu's visual tree.
if (menuIsOpen)
{
- matches = matches.Where(x => MainMenu.IsVisualAncestorOf(x));
+ matches = matches.Where(x => x is not null && MainMenu!.IsVisualAncestorOf(x));
}
var match = matches.FirstOrDefault();
diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs
index c2197ee64d..def0a26b27 100644
--- a/src/Avalonia.Input/InputElement.cs
+++ b/src/Avalonia.Input/InputElement.cs
@@ -675,7 +675,7 @@ namespace Avalonia.Input
/// .
///
/// The parent control.
- private void UpdateIsEffectivelyEnabled(InputElement parent)
+ private void UpdateIsEffectivelyEnabled(InputElement? parent)
{
IsEffectivelyEnabled = IsEnabledCore && (parent?.IsEffectivelyEnabled ?? true);
diff --git a/src/Avalonia.Input/Pointer.cs b/src/Avalonia.Input/Pointer.cs
index 433b275ce4..3012f07f6a 100644
--- a/src/Avalonia.Input/Pointer.cs
+++ b/src/Avalonia.Input/Pointer.cs
@@ -54,7 +54,7 @@ namespace Avalonia.Input
Captured.DetachedFromVisualTree += OnCaptureDetached;
}
- IInputElement GetNextCapture(IVisual parent)
+ IInputElement? GetNextCapture(IVisual parent)
{
return parent as IInputElement ?? parent.FindAncestorOfType();
}
diff --git a/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs
index ba7a3868c7..a2c4b0313b 100644
--- a/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs
+++ b/src/Avalonia.Visuals/Animation/Animators/BaseBrushAnimator.cs
@@ -143,7 +143,7 @@ namespace Avalonia.Animation.Animators
if (!match(firstKeyType))
continue;
- animator = (IAnimator)Activator.CreateInstance(animatorType);
+ animator = (IAnimator?)Activator.CreateInstance(animatorType);
if (animator != null)
{
animator.Property = Property;
diff --git a/src/Avalonia.Visuals/Animation/Animators/TransformAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/TransformAnimator.cs
index 1b2142f6c9..1d7bfd3748 100644
--- a/src/Avalonia.Visuals/Animation/Animators/TransformAnimator.cs
+++ b/src/Avalonia.Visuals/Animation/Animators/TransformAnimator.cs
@@ -11,10 +11,10 @@ namespace Avalonia.Animation.Animators
///
public class TransformAnimator : Animator
{
- DoubleAnimator _doubleAnimator;
+ DoubleAnimator? _doubleAnimator;
///
- public override IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable obsMatch, Action onComplete)
+ public override IDisposable? Apply(Animation animation, Animatable control, IClock clock, IObservable obsMatch, Action onComplete)
{
var ctrl = (Visual)control;
diff --git a/src/Avalonia.Visuals/Animation/CompositePageTransition.cs b/src/Avalonia.Visuals/Animation/CompositePageTransition.cs
index 2deebd7792..2a6eae3e38 100644
--- a/src/Avalonia.Visuals/Animation/CompositePageTransition.cs
+++ b/src/Avalonia.Visuals/Animation/CompositePageTransition.cs
@@ -37,7 +37,7 @@ namespace Avalonia.Animation
public List PageTransitions { get; set; } = new List();
///
- public Task Start(Visual from, Visual to, bool forward, CancellationToken cancellationToken)
+ public Task Start(Visual? from, Visual? to, bool forward, CancellationToken cancellationToken)
{
var transitionTasks = PageTransitions
.Select(transition => transition.Start(from, to, forward, cancellationToken))
diff --git a/src/Avalonia.Visuals/Animation/CrossFade.cs b/src/Avalonia.Visuals/Animation/CrossFade.cs
index 5eaa920b32..608a0880ec 100644
--- a/src/Avalonia.Visuals/Animation/CrossFade.cs
+++ b/src/Avalonia.Visuals/Animation/CrossFade.cs
@@ -100,7 +100,7 @@ namespace Avalonia.Animation
}
///
- public async Task Start(Visual from, Visual to, CancellationToken cancellationToken)
+ public async Task Start(Visual? from, Visual? to, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -112,7 +112,7 @@ namespace Avalonia.Animation
{
if (to != null)
{
- disposables.Add(to.SetValue(Visual.OpacityProperty, 0, Data.BindingPriority.Animation));
+ disposables.Add(to.SetValue(Visual.OpacityProperty, 0, Data.BindingPriority.Animation)!);
}
if (from != null)
@@ -151,7 +151,7 @@ namespace Avalonia.Animation
///
/// A that tracks the progress of the animation.
///
- Task IPageTransition.Start(Visual from, Visual to, bool forward, CancellationToken cancellationToken)
+ Task IPageTransition.Start(Visual? from, Visual? to, bool forward, CancellationToken cancellationToken)
{
return Start(from, to, cancellationToken);
}
diff --git a/src/Avalonia.Visuals/Animation/IPageTransition.cs b/src/Avalonia.Visuals/Animation/IPageTransition.cs
index 2d19ddbb5b..5abfdbbd0d 100644
--- a/src/Avalonia.Visuals/Animation/IPageTransition.cs
+++ b/src/Avalonia.Visuals/Animation/IPageTransition.cs
@@ -26,6 +26,6 @@ namespace Avalonia.Animation
///
/// A that tracks the progress of the animation.
///
- Task Start(Visual from, Visual to, bool forward, CancellationToken cancellationToken);
+ Task Start(Visual? from, Visual? to, bool forward, CancellationToken cancellationToken);
}
}
diff --git a/src/Avalonia.Visuals/Animation/PageSlide.cs b/src/Avalonia.Visuals/Animation/PageSlide.cs
index 7d033ccf61..b5a6062593 100644
--- a/src/Avalonia.Visuals/Animation/PageSlide.cs
+++ b/src/Avalonia.Visuals/Animation/PageSlide.cs
@@ -62,7 +62,7 @@ namespace Avalonia.Animation
public Easing SlideOutEasing { get; set; } = new LinearEasing();
///
- public async Task Start(Visual from, Visual to, bool forward, CancellationToken cancellationToken)
+ public async Task Start(Visual? from, Visual? to, bool forward, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -155,17 +155,17 @@ namespace Avalonia.Animation
///
/// Any one of the parameters may be null, but not both.
///
- private static IVisual GetVisualParent(IVisual from, IVisual to)
+ private static IVisual GetVisualParent(IVisual? from, IVisual? to)
{
- var p1 = (from ?? to).VisualParent;
- var p2 = (to ?? from).VisualParent;
+ var p1 = (from ?? to)!.VisualParent;
+ var p2 = (to ?? from)!.VisualParent;
if (p1 != null && p2 != null && p1 != p2)
{
throw new ArgumentException("Controls for PageSlide must have same parent.");
}
- return p1;
+ return p1 ?? throw new InvalidOperationException("Cannot determine visual parent.");
}
}
}
diff --git a/src/Avalonia.Visuals/Animation/RenderLoopClock.cs b/src/Avalonia.Visuals/Animation/RenderLoopClock.cs
index 504caef461..942e7eb7c6 100644
--- a/src/Avalonia.Visuals/Animation/RenderLoopClock.cs
+++ b/src/Avalonia.Visuals/Animation/RenderLoopClock.cs
@@ -9,7 +9,9 @@ namespace Avalonia.Animation
{
protected override void Stop()
{
- AvaloniaLocator.Current.GetService().Remove(this);
+ var loop = AvaloniaLocator.Current.GetService() ??
+ throw new InvalidOperationException("Unable to locate IRenderLoop.");
+ loop.Remove(this);
}
bool IRenderLoopTask.NeedsUpdate => HasSubscriptions;
diff --git a/src/Avalonia.Visuals/ApiCompatBaseline.txt b/src/Avalonia.Visuals/ApiCompatBaseline.txt
index ee4f70e074..ad9a5fd71a 100644
--- a/src/Avalonia.Visuals/ApiCompatBaseline.txt
+++ b/src/Avalonia.Visuals/ApiCompatBaseline.txt
@@ -5,6 +5,8 @@ InterfacesShouldHaveSameMembers : Interface member 'public System.Threading.Task
MembersMustExist : Member 'public System.Threading.Tasks.Task Avalonia.Animation.IPageTransition.Start(Avalonia.Visual, Avalonia.Visual, System.Boolean)' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Threading.Tasks.Task Avalonia.Animation.IPageTransition.Start(Avalonia.Visual, Avalonia.Visual, System.Boolean, System.Threading.CancellationToken)' is present in the implementation but not in the contract.
MembersMustExist : Member 'public System.Threading.Tasks.Task Avalonia.Animation.PageSlide.Start(Avalonia.Visual, Avalonia.Visual, System.Boolean)' does not exist in the implementation but it does exist in the contract.
+MembersMustExist : Member 'public void Avalonia.Media.GlyphRun..ctor()' does not exist in the implementation but it does exist in the contract.
+MembersMustExist : Member 'public void Avalonia.Media.GlyphRun.GlyphTypeface.set(Avalonia.Media.GlyphTypeface)' does not exist in the implementation but it does exist in the contract.
TypeCannotChangeClassification : Type 'Avalonia.Media.Immutable.ImmutableSolidColorBrush' is a 'class' in the implementation but is a 'struct' in the contract.
MembersMustExist : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext)' does not exist in the implementation but it does exist in the contract.
CannotAddAbstractMembers : Member 'public void Avalonia.Media.TextFormatting.DrawableTextRun.Draw(Avalonia.Media.DrawingContext, Avalonia.Point)' is abstract in the implementation but is missing in the contract.
@@ -77,4 +79,4 @@ InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IWr
InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IWriteableBitmapImpl Avalonia.Platform.IPlatformRenderInterface.LoadWriteableBitmap(System.String)' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IWriteableBitmapImpl Avalonia.Platform.IPlatformRenderInterface.LoadWriteableBitmapToHeight(System.IO.Stream, System.Int32, Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode)' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public Avalonia.Platform.IWriteableBitmapImpl Avalonia.Platform.IPlatformRenderInterface.LoadWriteableBitmapToWidth(System.IO.Stream, System.Int32, Avalonia.Visuals.Media.Imaging.BitmapInterpolationMode)' is present in the implementation but not in the contract.
-Total Issues: 78
+Total Issues: 79
diff --git a/src/Avalonia.Visuals/Avalonia.Visuals.csproj b/src/Avalonia.Visuals/Avalonia.Visuals.csproj
index 51ebfcb11f..486f08913c 100644
--- a/src/Avalonia.Visuals/Avalonia.Visuals.csproj
+++ b/src/Avalonia.Visuals/Avalonia.Visuals.csproj
@@ -15,4 +15,5 @@
+
diff --git a/src/Avalonia.Visuals/CornerRadius.cs b/src/Avalonia.Visuals/CornerRadius.cs
index 037bb16e31..893f7c4565 100644
--- a/src/Avalonia.Visuals/CornerRadius.cs
+++ b/src/Avalonia.Visuals/CornerRadius.cs
@@ -91,7 +91,7 @@ namespace Avalonia
///
/// The Object to compare against.
/// True if the Object is equal to this corner radius; False otherwise.
- public override bool Equals(object obj) => obj is CornerRadius other && Equals(other);
+ public override bool Equals(object? obj) => obj is CornerRadius other && Equals(other);
public override int GetHashCode()
{
diff --git a/src/Avalonia.Visuals/Matrix.cs b/src/Avalonia.Visuals/Matrix.cs
index 243dafe817..b08a0eb98a 100644
--- a/src/Avalonia.Visuals/Matrix.cs
+++ b/src/Avalonia.Visuals/Matrix.cs
@@ -272,7 +272,7 @@ namespace Avalonia
///
/// The Object to compare against.
/// True if the Object is equal to this matrix; False otherwise.
- public override bool Equals(object obj) => obj is Matrix other && Equals(other);
+ public override bool Equals(object? obj) => obj is Matrix other && Equals(other);
///
/// Returns the hash code for this instance.
diff --git a/src/Avalonia.Visuals/Media/BoxShadow.cs b/src/Avalonia.Visuals/Media/BoxShadow.cs
index 50f75365b0..b01f59f5f8 100644
--- a/src/Avalonia.Visuals/Media/BoxShadow.cs
+++ b/src/Avalonia.Visuals/Media/BoxShadow.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using Avalonia.Animation.Animators;
@@ -26,7 +27,7 @@ namespace Avalonia.Media
return OffsetX.Equals(other.OffsetX) && OffsetY.Equals(other.OffsetY) && Blur.Equals(other.Blur) && Spread.Equals(other.Spread) && Color.Equals(other.Color);
}
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
return obj is BoxShadow other && Equals(other);
}
@@ -59,7 +60,7 @@ namespace Avalonia.Media
_index = 0;
}
- public bool TryReadString(out string s)
+ public bool TryReadString([MaybeNullWhen(false)] out string s)
{
s = null;
if (_index >= _arr.Length)
@@ -152,11 +153,11 @@ namespace Avalonia.Media
tokenizer.TryReadString(out var token5);
if (token4 != null)
- blur = double.Parse(token3, CultureInfo.InvariantCulture);
+ blur = double.Parse(token3!, CultureInfo.InvariantCulture);
if (token5 != null)
- spread = double.Parse(token4, CultureInfo.InvariantCulture);
+ spread = double.Parse(token4!, CultureInfo.InvariantCulture);
- var color = Color.Parse(token5 ?? token4 ?? token3);
+ var color = Color.Parse(token5 ?? token4 ?? token3!);
return new BoxShadow
{
IsInset = inset,
diff --git a/src/Avalonia.Visuals/Media/BoxShadows.cs b/src/Avalonia.Visuals/Media/BoxShadows.cs
index 810ac70b99..4614ea4e3c 100644
--- a/src/Avalonia.Visuals/Media/BoxShadows.cs
+++ b/src/Avalonia.Visuals/Media/BoxShadows.cs
@@ -8,7 +8,7 @@ namespace Avalonia.Media
public struct BoxShadows
{
private readonly BoxShadow _first;
- private readonly BoxShadow[] _list;
+ private readonly BoxShadow[]? _list;
public int Count { get; }
static BoxShadows()
@@ -39,7 +39,7 @@ namespace Avalonia.Media
throw new IndexOutOfRangeException();
if (c == 0)
return _first;
- return _list[c - 1];
+ return _list![c - 1];
}
}
@@ -134,7 +134,7 @@ namespace Avalonia.Media
return true;
}
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
return obj is BoxShadows other && Equals(other);
}
diff --git a/src/Avalonia.Visuals/Media/Brush.cs b/src/Avalonia.Visuals/Media/Brush.cs
index cf7f5f531c..11fbe9393a 100644
--- a/src/Avalonia.Visuals/Media/Brush.cs
+++ b/src/Avalonia.Visuals/Media/Brush.cs
@@ -19,7 +19,7 @@ namespace Avalonia.Media
AvaloniaProperty.Register(nameof(Opacity), 1.0);
///
- public event EventHandler Invalidated;
+ public event EventHandler? Invalidated;
static Brush()
{
@@ -43,18 +43,20 @@ namespace Avalonia.Media
/// The .
public static IBrush Parse(string s)
{
- Contract.Requires(s != null);
- Contract.Requires(s.Length > 0);
+ _ = s ?? throw new ArgumentNullException(nameof(s));
- if (s[0] == '#')
+ if (s.Length > 0)
{
- return new ImmutableSolidColorBrush(Color.Parse(s));
- }
+ if (s[0] == '#')
+ {
+ return new ImmutableSolidColorBrush(Color.Parse(s));
+ }
- var brush = KnownColors.GetKnownBrush(s);
- if (brush != null)
- {
- return brush;
+ var brush = KnownColors.GetKnownBrush(s);
+ if (brush != null)
+ {
+ return brush;
+ }
}
throw new FormatException($"Invalid brush string: '{s}'.");
diff --git a/src/Avalonia.Visuals/Media/BrushConverter.cs b/src/Avalonia.Visuals/Media/BrushConverter.cs
index b3c105ffc7..c501835c15 100644
--- a/src/Avalonia.Visuals/Media/BrushConverter.cs
+++ b/src/Avalonia.Visuals/Media/BrushConverter.cs
@@ -9,14 +9,14 @@ namespace Avalonia.Media
///
public class BrushConverter : TypeConverter
{
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
+ public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
return sourceType == typeof(string);
}
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
+ public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
{
- return Brush.Parse((string)value);
+ return value is string s ? Brush.Parse(s) : null;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Avalonia.Visuals/Media/BrushExtensions.cs b/src/Avalonia.Visuals/Media/BrushExtensions.cs
index 87e698e705..2fc8778a5e 100644
--- a/src/Avalonia.Visuals/Media/BrushExtensions.cs
+++ b/src/Avalonia.Visuals/Media/BrushExtensions.cs
@@ -18,7 +18,7 @@ namespace Avalonia.Media
///
public static IBrush ToImmutable(this IBrush brush)
{
- Contract.Requires(brush != null);
+ _ = brush ?? throw new ArgumentNullException(nameof(brush));
return (brush as IMutableBrush)?.ToImmutable() ?? brush;
}
@@ -33,7 +33,7 @@ namespace Avalonia.Media
///
public static ImmutableDashStyle ToImmutable(this IDashStyle style)
{
- Contract.Requires(style != null);
+ _ = style ?? throw new ArgumentNullException(nameof(style));
return style as ImmutableDashStyle ?? ((DashStyle)style).ToImmutable();
}
@@ -48,7 +48,7 @@ namespace Avalonia.Media
///
public static ImmutablePen ToImmutable(this IPen pen)
{
- Contract.Requires(pen != null);
+ _ = pen ?? throw new ArgumentNullException(nameof(pen));
return pen as ImmutablePen ?? ((Pen)pen).ToImmutable();
}
diff --git a/src/Avalonia.Visuals/Media/CharacterHit.cs b/src/Avalonia.Visuals/Media/CharacterHit.cs
index f018b2d8a9..6bbbff4f5b 100644
--- a/src/Avalonia.Visuals/Media/CharacterHit.cs
+++ b/src/Avalonia.Visuals/Media/CharacterHit.cs
@@ -41,7 +41,7 @@ namespace Avalonia.Media
return FirstCharacterIndex == other.FirstCharacterIndex && TrailingLength == other.TrailingLength;
}
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
return obj is CharacterHit other && Equals(other);
}
diff --git a/src/Avalonia.Visuals/Media/Color.cs b/src/Avalonia.Visuals/Media/Color.cs
index a57a962db4..083c15cd13 100644
--- a/src/Avalonia.Visuals/Media/Color.cs
+++ b/src/Avalonia.Visuals/Media/Color.cs
@@ -280,7 +280,7 @@ namespace Avalonia.Media
return A == other.A && R == other.R && G == other.G && B == other.B;
}
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
return obj is Color other && Equals(other);
}
diff --git a/src/Avalonia.Visuals/Media/DashStyle.cs b/src/Avalonia.Visuals/Media/DashStyle.cs
index acba2d3615..2ec9436ede 100644
--- a/src/Avalonia.Visuals/Media/DashStyle.cs
+++ b/src/Avalonia.Visuals/Media/DashStyle.cs
@@ -133,7 +133,7 @@ namespace Avalonia.Media
}
}
- private void DashesChanged(object sender, NotifyCollectionChangedEventArgs e)
+ private void DashesChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
Invalidated?.Invoke(this, e);
}
diff --git a/src/Avalonia.Visuals/Media/DrawingContext.cs b/src/Avalonia.Visuals/Media/DrawingContext.cs
index 8e8b116a04..2fbef8c89f 100644
--- a/src/Avalonia.Visuals/Media/DrawingContext.cs
+++ b/src/Avalonia.Visuals/Media/DrawingContext.cs
@@ -20,9 +20,9 @@ namespace Avalonia.Media
private static ThreadSafeObjectPool> TransformStackPool { get; } =
ThreadSafeObjectPool>.Default;
- private Stack _states = StateStackPool.Get();
+ private Stack? _states = StateStackPool.Get();
- private Stack _transformContainers = TransformStackPool.Get();
+ private Stack? _transformContainers = TransformStackPool.Get();
readonly struct TransformContainer
{
@@ -80,7 +80,7 @@ namespace Avalonia.Media
/// The rect in the output to draw to.
public void DrawImage(IImage source, Rect rect)
{
- Contract.Requires(source != null);
+ _ = source ?? throw new ArgumentNullException(nameof(source));
DrawImage(source, new Rect(source.Size), rect);
}
@@ -94,7 +94,7 @@ namespace Avalonia.Media
/// The bitmap interpolation mode.
public void DrawImage(IImage source, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = default)
{
- Contract.Requires(source != null);
+ _ = source ?? throw new ArgumentNullException(nameof(source));
source.Draw(this, sourceRect, destRect, bitmapInterpolationMode);
}
@@ -121,7 +121,8 @@ namespace Avalonia.Media
/// The geometry.
public void DrawGeometry(IBrush brush, IPen pen, Geometry geometry)
{
- DrawGeometry(brush, pen, geometry.PlatformImpl);
+ if (geometry.PlatformImpl is not null)
+ DrawGeometry(brush, pen, geometry.PlatformImpl);
}
///
@@ -132,7 +133,7 @@ namespace Avalonia.Media
/// The geometry.
public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry)
{
- Contract.Requires(geometry != null);
+ _ = geometry ?? throw new ArgumentNullException(nameof(geometry));
if (brush != null || PenIsVisible(pen))
{
@@ -157,7 +158,7 @@ namespace Avalonia.Media
/// The brush and the pen can both be null. If the brush is null, then no fill is performed.
/// If the pen is null, then no stoke is performed. If both the pen and the brush are null, then the drawing is not visible.
///
- public void DrawRectangle(IBrush brush, IPen pen, Rect rect, double radiusX = 0, double radiusY = 0,
+ public void DrawRectangle(IBrush? brush, IPen? pen, Rect rect, double radiusX = 0, double radiusY = 0,
BoxShadows boxShadows = default)
{
if (brush == null && !PenIsVisible(pen))
@@ -201,7 +202,7 @@ namespace Avalonia.Media
/// The brush and the pen can both be null. If the brush is null, then no fill is performed.
/// If the pen is null, then no stoke is performed. If both the pen and the brush are null, then the drawing is not visible.
///
- public void DrawEllipse(IBrush brush, IPen pen, Point center, double radiusX, double radiusY)
+ public void DrawEllipse(IBrush? brush, IPen? pen, Point center, double radiusX, double radiusY)
{
if (brush == null && !PenIsVisible(pen))
{
@@ -230,7 +231,7 @@ namespace Avalonia.Media
/// The text.
public void DrawText(IBrush foreground, Point origin, FormattedText text)
{
- Contract.Requires(text != null);
+ _ = text ?? throw new ArgumentNullException(nameof(text));
if (foreground != null)
{
@@ -245,7 +246,7 @@ namespace Avalonia.Media
/// The glyph run.
public void DrawGlyphRun(IBrush foreground, GlyphRun glyphRun)
{
- Contract.Requires(glyphRun != null);
+ _ = glyphRun ?? throw new ArgumentNullException(nameof(glyphRun));
if (foreground != null)
{
@@ -279,11 +280,14 @@ namespace Avalonia.Media
Clip,
MatrixContainer,
GeometryClip,
- OpacityMask
+ OpacityMask,
}
public PushedState(DrawingContext context, PushedStateType type, Matrix matrix = default(Matrix))
{
+ if (context._states is null)
+ throw new ObjectDisposedException(nameof(DrawingContext));
+
_context = context;
_type = type;
_matrix = matrix;
@@ -295,6 +299,8 @@ namespace Avalonia.Media
{
if (_type == PushedStateType.None)
return;
+ if (_context._states is null || _context._transformContainers is null)
+ throw new ObjectDisposedException(nameof(DrawingContext));
if (_context._currentLevel != _level)
throw new InvalidOperationException("Wrong Push/Pop state order");
_context._currentLevel--;
@@ -343,7 +349,14 @@ namespace Avalonia.Media
/// A disposable used to undo the clip geometry.
public PushedState PushGeometryClip(Geometry clip)
{
- Contract.Requires(clip != null);
+ _ = clip ?? throw new ArgumentNullException(nameof(clip));
+
+ // HACK: This check was added when nullable annotations pointed out that we're potentially
+ // pushing a null value for the clip here. Ideally we'd return an empty PushedState here but
+ // I don't want to make that change as part of adding nullable annotations.
+ if (clip.PlatformImpl is null)
+ throw new InvalidOperationException("Cannot push empty geometry clip.");
+
PlatformImpl.PushGeometryClip(clip.PlatformImpl);
return new PushedState(this, PushedState.PushedStateType.GeometryClip);
}
@@ -407,6 +420,8 @@ namespace Avalonia.Media
/// A disposable used to undo the transformation.
public PushedState PushTransformContainer()
{
+ if (_transformContainers is null)
+ throw new ObjectDisposedException(nameof(DrawingContext));
_transformContainers.Push(new TransformContainer(CurrentTransform, _currentContainerTransform));
_currentContainerTransform = CurrentTransform * _currentContainerTransform;
_currentTransform = Matrix.Identity;
@@ -418,6 +433,8 @@ namespace Avalonia.Media
///
public void Dispose()
{
+ if (_states is null || _transformContainers is null)
+ throw new ObjectDisposedException(nameof(DrawingContext));
while (_states.Count != 0)
_states.Peek().Dispose();
StateStackPool.Return(_states);
@@ -430,7 +447,7 @@ namespace Avalonia.Media
PlatformImpl.Dispose();
}
- private static bool PenIsVisible(IPen pen)
+ private static bool PenIsVisible(IPen? pen)
{
return pen?.Brush != null && pen.Thickness > 0;
}
diff --git a/src/Avalonia.Visuals/Media/DrawingImage.cs b/src/Avalonia.Visuals/Media/DrawingImage.cs
index 6fa8d397a5..488822b693 100644
--- a/src/Avalonia.Visuals/Media/DrawingImage.cs
+++ b/src/Avalonia.Visuals/Media/DrawingImage.cs
@@ -26,7 +26,7 @@ namespace Avalonia.Media
AvaloniaProperty.Register(nameof(Drawing));
///
- public event EventHandler Invalidated;
+ public event EventHandler? Invalidated;
///
/// Gets or sets the drawing content.
diff --git a/src/Avalonia.Visuals/Media/EllipseGeometry.cs b/src/Avalonia.Visuals/Media/EllipseGeometry.cs
index bae6dc3d8c..7f9abaf531 100644
--- a/src/Avalonia.Visuals/Media/EllipseGeometry.cs
+++ b/src/Avalonia.Visuals/Media/EllipseGeometry.cs
@@ -1,3 +1,4 @@
+using System;
using Avalonia.Platform;
namespace Avalonia.Media
@@ -95,9 +96,10 @@ namespace Avalonia.Media
}
///
- protected override IGeometryImpl CreateDefiningGeometry()
+ protected override IGeometryImpl? CreateDefiningGeometry()
{
- var factory = AvaloniaLocator.Current.GetService();
+ var factory = AvaloniaLocator.Current.GetService() ??
+ throw new InvalidOperationException("Unable to locate IPlatformRenderInterface.");
if (Rect != default) return factory.CreateEllipseGeometry(Rect);
diff --git a/src/Avalonia.Visuals/Media/ExperimentalAcrylicMaterial.cs b/src/Avalonia.Visuals/Media/ExperimentalAcrylicMaterial.cs
index 6b699acd2e..cdea5f5fa3 100644
--- a/src/Avalonia.Visuals/Media/ExperimentalAcrylicMaterial.cs
+++ b/src/Avalonia.Visuals/Media/ExperimentalAcrylicMaterial.cs
@@ -78,7 +78,7 @@ namespace Avalonia.Media
AvaloniaProperty.Register(nameof(FallbackColor));
///
- public event EventHandler Invalidated;
+ public event EventHandler? Invalidated;
///
/// Gets or Sets the BackgroundSource .
@@ -299,14 +299,14 @@ namespace Avalonia.Media
var lightness = (max + min) / 2.0;
- lightness = 1 - ((1 - lightness) * luminosityOpacity.Value);
+ lightness = 1 - ((1 - lightness) * (luminosityOpacity ?? 1));
lightness = 0.13 + (lightness * 0.74);
var luminosityColor = new Color(255, Trim(lightness), Trim(lightness), Trim(lightness));
var compensationMultiplier = 1 - PlatformTransparencyCompensationLevel;
- return new Color((byte)(255 * Math.Max(Math.Min(PlatformTransparencyCompensationLevel + (luminosityOpacity.Value * compensationMultiplier), 1.0), 0.0)), luminosityColor.R, luminosityColor.G, luminosityColor.B);
+ return new Color((byte)(255 * Math.Max(Math.Min(PlatformTransparencyCompensationLevel + ((luminosityOpacity ?? 1) * compensationMultiplier), 1.0), 0.0)), luminosityColor.R, luminosityColor.G, luminosityColor.B);
}
///
diff --git a/src/Avalonia.Visuals/Media/FontFallback.cs b/src/Avalonia.Visuals/Media/FontFallback.cs
index 240604c5c1..8943b57b31 100644
--- a/src/Avalonia.Visuals/Media/FontFallback.cs
+++ b/src/Avalonia.Visuals/Media/FontFallback.cs
@@ -8,7 +8,7 @@
///
/// Get or set the fallback
///
- public FontFamily FontFamily { get; set; }
+ public FontFamily FontFamily { get; set; } = FontFamily.Default;
///
/// Get or set the that is covered by the fallback.
diff --git a/src/Avalonia.Visuals/Media/FontFamily.cs b/src/Avalonia.Visuals/Media/FontFamily.cs
index f018733235..c4ebc1e0d4 100644
--- a/src/Avalonia.Visuals/Media/FontFamily.cs
+++ b/src/Avalonia.Visuals/Media/FontFamily.cs
@@ -27,7 +27,7 @@ namespace Avalonia.Media
/// Specifies the base uri that is used to resolve font family assets.
/// The name of the .
/// Base uri must be an absolute uri.
- public FontFamily(Uri baseUri, string name)
+ public FontFamily(Uri? baseUri, string name)
{
if (string.IsNullOrEmpty(name))
{
@@ -77,7 +77,7 @@ namespace Avalonia.Media
/// The family key.
///
/// Key is only used for custom fonts.
- public FontFamilyKey Key { get; }
+ public FontFamilyKey? Key { get; }
///
/// Returns True if this instance is the system's default.
@@ -95,7 +95,7 @@ namespace Avalonia.Media
private struct FontFamilyIdentifier
{
- public FontFamilyIdentifier(string name, Uri source)
+ public FontFamilyIdentifier(string name, Uri? source)
{
Name = name;
Source = source;
@@ -103,7 +103,7 @@ namespace Avalonia.Media
public string Name { get; }
- public Uri Source { get; }
+ public Uri? Source { get; }
}
private static FontFamilyIdentifier GetFontFamilyIdentifier(string name)
@@ -152,7 +152,7 @@ namespace Avalonia.Media
///
/// Specified family is not supported.
///
- public static FontFamily Parse(string s, Uri baseUri)
+ public static FontFamily Parse(string s, Uri? baseUri)
{
if (string.IsNullOrEmpty(s))
{
@@ -192,12 +192,12 @@ namespace Avalonia.Media
}
}
- public static bool operator !=(FontFamily a, FontFamily b)
+ public static bool operator !=(FontFamily? a, FontFamily? b)
{
return !(a == b);
}
- public static bool operator ==(FontFamily a, FontFamily b)
+ public static bool operator ==(FontFamily? a, FontFamily? b)
{
if (ReferenceEquals(a, b))
{
@@ -207,7 +207,7 @@ namespace Avalonia.Media
return !(a is null) && a.Equals(b);
}
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
if (ReferenceEquals(this, obj))
{
diff --git a/src/Avalonia.Visuals/Media/FontManager.cs b/src/Avalonia.Visuals/Media/FontManager.cs
index 33e7bf0200..72c1c8dcac 100644
--- a/src/Avalonia.Visuals/Media/FontManager.cs
+++ b/src/Avalonia.Visuals/Media/FontManager.cs
@@ -16,7 +16,7 @@ namespace Avalonia.Media
private readonly ConcurrentDictionary _glyphTypefaceCache =
new ConcurrentDictionary();
private readonly FontFamily _defaultFontFamily;
- private readonly IReadOnlyList _fontFallbacks;
+ private readonly IReadOnlyList? _fontFallbacks;
public FontManager(IFontManagerImpl platformImpl)
{
@@ -105,7 +105,7 @@ namespace Avalonia.Media
if (typeface.FontFamily == _defaultFontFamily)
{
- return null;
+ throw new InvalidOperationException($"Could not create glyph typeface for: {typeface.FontFamily.Name}.");
}
typeface = new Typeface(_defaultFontFamily, typeface.Style, typeface.Weight);
@@ -126,7 +126,7 @@ namespace Avalonia.Media
///
public bool TryMatchCharacter(int codepoint, FontStyle fontStyle,
FontWeight fontWeight,
- FontFamily fontFamily, CultureInfo culture, out Typeface typeface)
+ FontFamily? fontFamily, CultureInfo? culture, out Typeface typeface)
{
if(_fontFallbacks != null)
{
diff --git a/src/Avalonia.Visuals/Media/FontManagerOptions.cs b/src/Avalonia.Visuals/Media/FontManagerOptions.cs
index 983fd6eb32..54227dce0f 100644
--- a/src/Avalonia.Visuals/Media/FontManagerOptions.cs
+++ b/src/Avalonia.Visuals/Media/FontManagerOptions.cs
@@ -4,8 +4,8 @@ namespace Avalonia.Media
{
public class FontManagerOptions
{
- public string DefaultFamilyName { get; set; }
+ public string? DefaultFamilyName { get; set; }
- public IReadOnlyList FontFallbacks { get; set; }
+ public IReadOnlyList? FontFallbacks { get; set; }
}
}
diff --git a/src/Avalonia.Visuals/Media/Fonts/FamilyNameCollection.cs b/src/Avalonia.Visuals/Media/Fonts/FamilyNameCollection.cs
index 96312a5466..99daaf2143 100644
--- a/src/Avalonia.Visuals/Media/Fonts/FamilyNameCollection.cs
+++ b/src/Avalonia.Visuals/Media/Fonts/FamilyNameCollection.cs
@@ -122,12 +122,12 @@ namespace Avalonia.Media.Fonts
}
}
- public static bool operator !=(FamilyNameCollection a, FamilyNameCollection b)
+ public static bool operator !=(FamilyNameCollection? a, FamilyNameCollection? b)
{
return !(a == b);
}
- public static bool operator ==(FamilyNameCollection a, FamilyNameCollection b)
+ public static bool operator ==(FamilyNameCollection? a, FamilyNameCollection? b)
{
if (ReferenceEquals(a, b))
{
@@ -144,7 +144,7 @@ namespace Avalonia.Media.Fonts
///
/// true if the specified is equal to this instance; otherwise, false.
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
if (!(obj is FamilyNameCollection other))
{
diff --git a/src/Avalonia.Visuals/Media/Fonts/FontFamilyKey.cs b/src/Avalonia.Visuals/Media/Fonts/FontFamilyKey.cs
index eee24e856d..f607c67fed 100644
--- a/src/Avalonia.Visuals/Media/Fonts/FontFamilyKey.cs
+++ b/src/Avalonia.Visuals/Media/Fonts/FontFamilyKey.cs
@@ -12,7 +12,7 @@ namespace Avalonia.Media.Fonts
///
///
///
- public FontFamilyKey(Uri source, Uri baseUri = null)
+ public FontFamilyKey(Uri source, Uri? baseUri = null)
{
Source = source ?? throw new ArgumentNullException(nameof(source));
@@ -27,7 +27,7 @@ namespace Avalonia.Media.Fonts
///
/// A base URI to use if is relative
///
- public Uri BaseUri { get; }
+ public Uri? BaseUri { get; }
///
/// Returns a hash code for this instance.
@@ -55,12 +55,12 @@ namespace Avalonia.Media.Fonts
}
}
- public static bool operator !=(FontFamilyKey a, FontFamilyKey b)
+ public static bool operator !=(FontFamilyKey? a, FontFamilyKey? b)
{
return !(a == b);
}
- public static bool operator ==(FontFamilyKey a, FontFamilyKey b)
+ public static bool operator ==(FontFamilyKey? a, FontFamilyKey? b)
{
if (ReferenceEquals(a, b))
{
@@ -77,7 +77,7 @@ namespace Avalonia.Media.Fonts
///
/// true if the specified is equal to this instance; otherwise, false.
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
if (!(obj is FontFamilyKey other))
{
diff --git a/src/Avalonia.Visuals/Media/Fonts/FontFamilyLoader.cs b/src/Avalonia.Visuals/Media/Fonts/FontFamilyLoader.cs
index 02298417a4..203c8dc221 100644
--- a/src/Avalonia.Visuals/Media/Fonts/FontFamilyLoader.cs
+++ b/src/Avalonia.Visuals/Media/Fonts/FontFamilyLoader.cs
@@ -32,7 +32,8 @@ namespace Avalonia.Media.Fonts
///
private static IEnumerable GetFontAssetsBySource(FontFamilyKey fontFamilyKey)
{
- var assetLoader = AvaloniaLocator.Current.GetService();
+ var assetLoader = AvaloniaLocator.Current.GetService() ??
+ throw new InvalidOperationException("Unable to locate IAssetLoader.");
var availableAssets = assetLoader.GetAssets(fontFamilyKey.Source, fontFamilyKey.BaseUri);
@@ -50,7 +51,8 @@ namespace Avalonia.Media.Fonts
///
private static IEnumerable GetFontAssetsByExpression(FontFamilyKey fontFamilyKey)
{
- var assetLoader = AvaloniaLocator.Current.GetService();
+ var assetLoader = AvaloniaLocator.Current.GetService() ??
+ throw new InvalidOperationException("Unable to locate IAssetLoader.");
var fileName = GetFileName(fontFamilyKey, out var fileExtension, out var location);
@@ -87,7 +89,7 @@ namespace Avalonia.Media.Fonts
{
fileExtension = "." + fontFamilyKey.Source.AbsolutePath.Split('.').LastOrDefault();
- var fileName = fontFamilyKey.Source.LocalPath.Replace(fileExtension, string.Empty).Split('.').LastOrDefault();
+ var fileName = fontFamilyKey.Source.LocalPath.Replace(fileExtension, string.Empty).Split('.').Last();
location = new Uri(fontFamilyKey.Source.AbsoluteUri.Replace("." + fileName + fileExtension, string.Empty), UriKind.RelativeOrAbsolute);
diff --git a/src/Avalonia.Visuals/Media/FormattedText.cs b/src/Avalonia.Visuals/Media/FormattedText.cs
index ddffbe7500..499761d96c 100644
--- a/src/Avalonia.Visuals/Media/FormattedText.cs
+++ b/src/Avalonia.Visuals/Media/FormattedText.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using Avalonia.Platform;
@@ -10,11 +11,11 @@ namespace Avalonia.Media
{
private readonly IPlatformRenderInterface _platform;
private Size _constraint = Size.Infinity;
- private IFormattedTextImpl _platformImpl;
- private IReadOnlyList _spans;
+ private IFormattedTextImpl? _platformImpl;
+ private IReadOnlyList? _spans;
private Typeface _typeface;
private double _fontSize;
- private string _text;
+ private string? _text;
private TextAlignment _textAlignment;
private TextWrapping _textWrapping;
@@ -23,7 +24,8 @@ namespace Avalonia.Media
///
public FormattedText()
{
- _platform = AvaloniaLocator.Current.GetService();
+ _platform = AvaloniaLocator.Current.GetService() ??
+ throw new InvalidOperationException("Unable to locate IPlatformRenderInterface.");
}
///
@@ -98,7 +100,7 @@ namespace Avalonia.Media
/// Gets or sets a collection of spans that describe the formatting of subsections of the
/// text.
///
- public IReadOnlyList Spans
+ public IReadOnlyList? Spans
{
get => _spans;
set => Set(ref _spans, value);
@@ -107,7 +109,7 @@ namespace Avalonia.Media
///
/// Gets or sets the text.
///
- public string Text
+ public string? Text
{
get => _text;
set => Set(ref _text, value);
@@ -141,7 +143,7 @@ namespace Avalonia.Media
if (_platformImpl == null)
{
_platformImpl = _platform.CreateFormattedText(
- _text,
+ _text ?? string.Empty,
_typeface,
_fontSize,
_textAlignment,
diff --git a/src/Avalonia.Visuals/Media/FormattedTextStyleSpan.cs b/src/Avalonia.Visuals/Media/FormattedTextStyleSpan.cs
index 92fdd651c3..fcb631d1eb 100644
--- a/src/Avalonia.Visuals/Media/FormattedTextStyleSpan.cs
+++ b/src/Avalonia.Visuals/Media/FormattedTextStyleSpan.cs
@@ -14,7 +14,7 @@
public FormattedTextStyleSpan(
int startIndex,
int length,
- IBrush foregroundBrush = null)
+ IBrush? foregroundBrush = null)
{
StartIndex = startIndex;
Length = length;
@@ -34,6 +34,6 @@
///
/// Gets the span's foreground brush.
///
- public IBrush ForegroundBrush { get; }
+ public IBrush? ForegroundBrush { get; }
}
}
diff --git a/src/Avalonia.Visuals/Media/Geometry.cs b/src/Avalonia.Visuals/Media/Geometry.cs
index ccef6665a9..76c67a5cf4 100644
--- a/src/Avalonia.Visuals/Media/Geometry.cs
+++ b/src/Avalonia.Visuals/Media/Geometry.cs
@@ -11,11 +11,11 @@ namespace Avalonia.Media
///
/// Defines the property.
///
- public static readonly StyledProperty TransformProperty =
- AvaloniaProperty.Register(nameof(Transform));
+ public static readonly StyledProperty TransformProperty =
+ AvaloniaProperty.Register(nameof(Transform));
private bool _isDirty = true;
- private IGeometryImpl _platformImpl;
+ private IGeometryImpl? _platformImpl;
static Geometry()
{
@@ -25,7 +25,7 @@ namespace Avalonia.Media
///
/// Raised when the geometry changes.
///
- public event EventHandler Changed;
+ public event EventHandler? Changed;
///
/// Gets the geometry's bounding rectangle.
@@ -35,7 +35,7 @@ namespace Avalonia.Media
///
/// Gets the platform-specific implementation of the geometry.
///
- public IGeometryImpl PlatformImpl
+ public IGeometryImpl? PlatformImpl
{
get
{
@@ -60,7 +60,7 @@ namespace Avalonia.Media
///
/// Gets or sets a transform to apply to the geometry.
///
- public Transform Transform
+ public Transform? Transform
{
get { return GetValue(TransformProperty); }
set { SetValue(TransformProperty, value); }
@@ -127,7 +127,7 @@ namespace Avalonia.Media
/// Creates the platform implementation of the geometry, without the transform applied.
///
///
- protected abstract IGeometryImpl CreateDefiningGeometry();
+ protected abstract IGeometryImpl? CreateDefiningGeometry();
///
/// Invalidates the platform implementation of the geometry.
@@ -141,8 +141,8 @@ namespace Avalonia.Media
private void TransformChanged(AvaloniaPropertyChangedEventArgs e)
{
- var oldValue = (Transform)e.OldValue;
- var newValue = (Transform)e.NewValue;
+ var oldValue = (Transform?)e.OldValue;
+ var newValue = (Transform?)e.NewValue;
if (oldValue != null)
{
@@ -157,9 +157,9 @@ namespace Avalonia.Media
TransformChanged(newValue, EventArgs.Empty);
}
- private void TransformChanged(object sender, EventArgs e)
+ private void TransformChanged(object? sender, EventArgs e)
{
- var transform = ((Transform)sender)?.Value;
+ var transform = ((Transform?)sender)?.Value;
if (_platformImpl is ITransformedGeometryImpl t)
{
@@ -174,7 +174,7 @@ namespace Avalonia.Media
}
else if (_platformImpl != null && transform != null && transform != Matrix.Identity)
{
- _platformImpl = PlatformImpl.WithTransform(transform.Value);
+ _platformImpl = _platformImpl.WithTransform(transform.Value);
}
Changed?.Invoke(this, EventArgs.Empty);
diff --git a/src/Avalonia.Visuals/Media/GlyphRun.cs b/src/Avalonia.Visuals/Media/GlyphRun.cs
index 234122f6f5..e15a19306a 100644
--- a/src/Avalonia.Visuals/Media/GlyphRun.cs
+++ b/src/Avalonia.Visuals/Media/GlyphRun.cs
@@ -14,7 +14,7 @@ namespace Avalonia.Media
private static readonly IComparer s_ascendingComparer = Comparer.Default;
private static readonly IComparer s_descendingComparer = new ReverseComparer();
- private IGlyphRunImpl _glyphRunImpl;
+ private IGlyphRunImpl? _glyphRunImpl;
private GlyphTypeface _glyphTypeface;
private double _fontRenderingEmSize;
private int _biDiLevel;
@@ -27,14 +27,6 @@ namespace Avalonia.Media
private ReadOnlySlice _glyphClusters;
private ReadOnlySlice _characters;
- ///
- /// Initializes a new instance of the class.
- ///
- public GlyphRun()
- {
-
- }
-
///
/// Initializes a new instance of the class by specifying properties of the class.
///
@@ -56,7 +48,7 @@ namespace Avalonia.Media
ReadOnlySlice glyphClusters = default,
int biDiLevel = 0)
{
- GlyphTypeface = glyphTypeface;
+ _glyphTypeface = glyphTypeface;
FontRenderingEmSize = fontRenderingEmSize;
@@ -74,13 +66,9 @@ namespace Avalonia.Media
}
///
- /// Gets or sets the for the .
+ /// Gets the for the .
///
- public GlyphTypeface GlyphTypeface
- {
- get => _glyphTypeface;
- set => Set(ref _glyphTypeface, value);
- }
+ public GlyphTypeface GlyphTypeface => _glyphTypeface;
///
/// Gets or sets the em size used for rendering the .
@@ -199,7 +187,7 @@ namespace Avalonia.Media
Initialize();
}
- return _glyphRunImpl;
+ return _glyphRunImpl!;
}
}
@@ -639,7 +627,8 @@ namespace Avalonia.Media
throw new InvalidOperationException();
}
- var platformRenderInterface = AvaloniaLocator.Current.GetService();
+ var platformRenderInterface = AvaloniaLocator.Current.GetService() ??
+ throw new InvalidOperationException("Unable to locate IPlatformRenderInterface");
_glyphRunImpl = platformRenderInterface.CreateGlyphRun(this);
}
@@ -651,7 +640,7 @@ namespace Avalonia.Media
private class ReverseComparer : IComparer
{
- public int Compare(T x, T y)
+ public int Compare(T? x, T? y)
{
return Comparer.Default.Compare(y, x);
}
diff --git a/src/Avalonia.Visuals/Media/GlyphTypeface.cs b/src/Avalonia.Visuals/Media/GlyphTypeface.cs
index 2be505b9c0..67dfbb84b6 100644
--- a/src/Avalonia.Visuals/Media/GlyphTypeface.cs
+++ b/src/Avalonia.Visuals/Media/GlyphTypeface.cs
@@ -8,8 +8,8 @@ namespace Avalonia.Media
public const int InvisibleGlyph = 3;
public GlyphTypeface(Typeface typeface)
- : this(FontManager.Current?.PlatformImpl.CreateGlyphTypeface(typeface))
- {
+ : this(FontManager.Current.PlatformImpl.CreateGlyphTypeface(typeface))
+ {
}
public GlyphTypeface(IGlyphTypefaceImpl platformImpl)
diff --git a/src/Avalonia.Visuals/Media/GradientBrush.cs b/src/Avalonia.Visuals/Media/GradientBrush.cs
index 5f795d4644..c84413ecbb 100644
--- a/src/Avalonia.Visuals/Media/GradientBrush.cs
+++ b/src/Avalonia.Visuals/Media/GradientBrush.cs
@@ -26,7 +26,7 @@ namespace Avalonia.Media
public static readonly StyledProperty GradientStopsProperty =
AvaloniaProperty.Register(nameof(GradientStops));
- private IDisposable _gradientStopsSubscription;
+ private IDisposable? _gradientStopsSubscription;
static GradientBrush()
{
@@ -64,13 +64,13 @@ namespace Avalonia.Media
{
if (e.Sender is GradientBrush brush)
{
- var oldValue = (GradientStops)e.OldValue;
- var newValue = (GradientStops)e.NewValue;
+ var oldValue = (GradientStops?)e.OldValue;
+ var newValue = (GradientStops?)e.NewValue;
if (oldValue != null)
{
oldValue.CollectionChanged -= brush.GradientStopsChanged;
- brush._gradientStopsSubscription.Dispose();
+ brush._gradientStopsSubscription?.Dispose();
}
if (newValue != null)
@@ -83,12 +83,12 @@ namespace Avalonia.Media
}
}
- private void GradientStopsChanged(object sender, NotifyCollectionChangedEventArgs e)
+ private void GradientStopsChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
RaiseInvalidated(EventArgs.Empty);
}
- private void GradientStopChanged(Tuple