diff --git a/src/Compatibility/Core/src/MacOS/Extensions/BrushExtensions.cs b/src/Compatibility/Core/src/MacOS/Extensions/BrushExtensions.cs index 68a95d68bac7..a7a291f07824 100644 --- a/src/Compatibility/Core/src/MacOS/Extensions/BrushExtensions.cs +++ b/src/Compatibility/Core/src/MacOS/Extensions/BrushExtensions.cs @@ -156,10 +156,11 @@ public static void RemoveBackgroundLayer(this CALayer layer) if (layer.Name == BackgroundLayer) layer?.RemoveFromSuperLayer(); - if (layer.Sublayers == null || layer.Sublayers.Count() == 0) + var sublayers = layer.Sublayers; + if (sublayers is null || sublayers.Length == 0) return; - foreach (var subLayer in layer.Sublayers) + foreach (var subLayer in sublayers) { if (subLayer.Name == BackgroundLayer) subLayer?.RemoveFromSuperLayer(); diff --git a/src/Controls/src/Core/Platform/iOS/Extensions/BrushExtensions.cs b/src/Controls/src/Core/Platform/iOS/Extensions/BrushExtensions.cs index a12f19761e8e..77c2e71f410f 100644 --- a/src/Controls/src/Core/Platform/iOS/Extensions/BrushExtensions.cs +++ b/src/Controls/src/Core/Platform/iOS/Extensions/BrushExtensions.cs @@ -164,10 +164,11 @@ public static void RemoveBackgroundLayer(this CALayer layer) if (layer.Name == BackgroundLayer) layer?.RemoveFromSuperLayer(); - if (layer.Sublayers == null || layer.Sublayers.Count() == 0) + var sublayers = layer.Sublayers; + if (sublayers is null || sublayers.Length == 0) return; - foreach (var subLayer in layer.Sublayers) + foreach (var subLayer in sublayers) { if (subLayer.Name == BackgroundLayer) subLayer?.RemoveFromSuperLayer(); @@ -187,9 +188,10 @@ public static void UpdateBackgroundLayer(this UIView view) static void UpdateBackgroundLayer(this CALayer layer, CGRect bounds) { - if (layer != null && layer.Sublayers != null) + var sublayers = layer?.Sublayers; + if (sublayers is not null) { - foreach (var sublayer in layer.Sublayers) + foreach (var sublayer in sublayers) { UpdateBackgroundLayer(sublayer, bounds); diff --git a/src/Core/src/Platform/iOS/LayerExtensions.cs b/src/Core/src/Platform/iOS/LayerExtensions.cs index 83ec7562f0ca..d91608fe0283 100644 --- a/src/Core/src/Platform/iOS/LayerExtensions.cs +++ b/src/Core/src/Platform/iOS/LayerExtensions.cs @@ -34,10 +34,11 @@ public static void RemoveBackgroundLayer(this UIView control) return; } - if (layer.Sublayers == null || layer.Sublayers.Length == 0) + var sublayers = layer.Sublayers; + if (sublayers is null || sublayers.Length == 0) return; - foreach (var subLayer in layer.Sublayers) + foreach (var subLayer in sublayers) { if (subLayer.Name == ViewExtensions.BackgroundLayerName) { diff --git a/src/Core/src/Platform/iOS/StrokeExtensions.cs b/src/Core/src/Platform/iOS/StrokeExtensions.cs index a59ebb81932f..3e97c13d2891 100644 --- a/src/Core/src/Platform/iOS/StrokeExtensions.cs +++ b/src/Core/src/Platform/iOS/StrokeExtensions.cs @@ -161,9 +161,10 @@ internal static void UpdateMauiCALayer(this UIView view) static void UpdateBackgroundLayer(this CALayer layer, CGRect bounds) { - if (layer != null && layer.Sublayers != null) + var sublayers = layer?.Sublayers; + if (sublayers is not null) { - foreach (var sublayer in layer.Sublayers) + foreach (var sublayer in sublayers) { UpdateBackgroundLayer(sublayer, bounds); diff --git a/src/Core/src/Platform/iOS/ViewExtensions.cs b/src/Core/src/Platform/iOS/ViewExtensions.cs index 45a7ef25b779..bec1da442bfc 100644 --- a/src/Core/src/Platform/iOS/ViewExtensions.cs +++ b/src/Core/src/Platform/iOS/ViewExtensions.cs @@ -250,12 +250,11 @@ public static void UpdateBackgroundLayerFrame(this UIView view) if (view == null || view.Frame.IsEmpty) return; - var layer = view.Layer; - - if (layer == null || layer.Sublayers == null || layer.Sublayers.Length == 0) + var sublayers = view.Layer?.Sublayers; + if (sublayers is null || sublayers.Length == 0) return; - foreach (var sublayer in layer.Sublayers) + foreach (var sublayer in sublayers) { if (sublayer.Name == BackgroundLayerName && sublayer.Frame != view.Bounds) { diff --git a/src/Core/src/Platform/iOS/WrapperView.cs b/src/Core/src/Platform/iOS/WrapperView.cs index da4a3d350ea5..d2ea8eee8f12 100644 --- a/src/Core/src/Platform/iOS/WrapperView.cs +++ b/src/Core/src/Platform/iOS/WrapperView.cs @@ -255,10 +255,11 @@ void DisposeBorder() CALayer? GetLayer() { - if (Layer is null || Layer.Sublayers is null) + var sublayers = Layer?.Sublayers; + if (sublayers is null) return null; - foreach (var subLayer in Layer.Sublayers) + foreach (var subLayer in sublayers) if (subLayer.Delegate is not null) return subLayer; @@ -267,10 +268,11 @@ void DisposeBorder() CALayer? GetBackgroundLayer() { - if (Layer is null || Layer.Sublayers is null) + var sublayers = Layer?.Sublayers; + if (sublayers is null) return null; - foreach (var subLayer in Layer.Sublayers) + foreach (var subLayer in sublayers) if (subLayer.Name == ViewExtensions.BackgroundLayerName) return subLayer; diff --git a/src/Essentials/src/Screenshot/Screenshot.ios.cs b/src/Essentials/src/Screenshot/Screenshot.ios.cs index abc967cd18ac..5336e2ab5e9f 100644 --- a/src/Essentials/src/Screenshot/Screenshot.ios.cs +++ b/src/Essentials/src/Screenshot/Screenshot.ios.cs @@ -137,10 +137,11 @@ static bool TryRender(CALayer layer, CGContext ctx, bool skipChildren, out Excep static void HideSublayers(CALayer layer, Dictionary visibilitySnapshot) { - if (layer.Sublayers == null) + var sublayers = layer?.Sublayers; + if (sublayers is null) return; - foreach (var sublayer in layer.Sublayers) + foreach (var sublayer in sublayers) { HideSublayers(sublayer, visibilitySnapshot);