diff --git a/.editorconfig b/.editorconfig index bb15c854ad1c..57fa5d295138 100644 --- a/.editorconfig +++ b/.editorconfig @@ -29,6 +29,7 @@ dotnet_diagnostic.CA1307.severity = error dotnet_diagnostic.CA1309.severity = error dotnet_diagnostic.CA1311.severity = error dotnet_diagnostic.CA1815.severity = error +dotnet_diagnostic.CA1825.severity = error # nullability checks diff --git a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue4597.cs b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue4597.cs index d4b4716378b1..64c9933054c7 100644 --- a/src/Compatibility/ControlGallery/src/Issues.Shared/Issue4597.cs +++ b/src/Compatibility/ControlGallery/src/Issues.Shared/Issue4597.cs @@ -290,7 +290,7 @@ Xamarin.UITest.Queries.AppResult TestForImageVisible() if (result[0].Rect.Height > 1) return result; - return new Xamarin.UITest.Queries.AppResult[0]; + return Array.Empty(); }, 10, 4000); Assert.AreEqual(1, images.Length); diff --git a/src/Compatibility/Core/src/Android/CollectionView/SelectableItemsViewAdapter.cs b/src/Compatibility/Core/src/Android/CollectionView/SelectableItemsViewAdapter.cs index d67e9263fce6..025a756859e2 100644 --- a/src/Compatibility/Core/src/Android/CollectionView/SelectableItemsViewAdapter.cs +++ b/src/Compatibility/Core/src/Android/CollectionView/SelectableItemsViewAdapter.cs @@ -81,13 +81,13 @@ int[] GetSelectedPositions() switch (ItemsView.SelectionMode) { case SelectionMode.None: - return new int[0]; + return Array.Empty(); case SelectionMode.Single: var selectedItem = ItemsView.SelectedItem; if (selectedItem == null) { - return new int[0]; + return Array.Empty(); } return new int[1] { GetPositionForItem(selectedItem) }; @@ -104,7 +104,7 @@ int[] GetSelectedPositions() return result; } - return new int[0]; + return Array.Empty(); } bool PositionIsSelected(int position) diff --git a/src/Compatibility/Core/src/Android/Renderers/EditorRenderer.cs b/src/Compatibility/Core/src/Android/Renderers/EditorRenderer.cs index 0b7400067e53..1944d8e6339d 100644 --- a/src/Compatibility/Core/src/Android/Renderers/EditorRenderer.cs +++ b/src/Compatibility/Core/src/Android/Renderers/EditorRenderer.cs @@ -293,7 +293,7 @@ void OnKeyboardBackPressed(object sender, EventArgs eventArgs) [PortHandler] void UpdateMaxLength() { - var currentFilters = new List(EditText?.GetFilters() ?? new IInputFilter[0]); + var currentFilters = new List(EditText?.GetFilters() ?? Array.Empty()); for (var i = 0; i < currentFilters.Count; i++) { diff --git a/src/Compatibility/Core/src/Android/Renderers/EntryRenderer.cs b/src/Compatibility/Core/src/Android/Renderers/EntryRenderer.cs index 9f7bb0ed6d61..f24922f5553f 100644 --- a/src/Compatibility/Core/src/Android/Renderers/EntryRenderer.cs +++ b/src/Compatibility/Core/src/Android/Renderers/EntryRenderer.cs @@ -379,7 +379,7 @@ void OnKeyboardBackPressed(object sender, EventArgs eventArgs) [PortHandler] void UpdateMaxLength() { - var currentFilters = new List(EditText?.GetFilters() ?? new IInputFilter[0]); + var currentFilters = new List(EditText?.GetFilters() ?? Array.Empty()); for (var i = 0; i < currentFilters.Count; i++) { diff --git a/src/Compatibility/Core/src/Android/Renderers/SearchBarRenderer.cs b/src/Compatibility/Core/src/Android/Renderers/SearchBarRenderer.cs index b40b130130a3..7ca278888378 100644 --- a/src/Compatibility/Core/src/Android/Renderers/SearchBarRenderer.cs +++ b/src/Compatibility/Core/src/Android/Renderers/SearchBarRenderer.cs @@ -290,7 +290,7 @@ void UpdateMaxLength() { _editText = _editText ?? Control.GetChildrenOfType().FirstOrDefault(); - var currentFilters = new List(_editText?.GetFilters() ?? new IInputFilter[0]); + var currentFilters = new List(_editText?.GetFilters() ?? Array.Empty()); for (var i = 0; i < currentFilters.Count; i++) { diff --git a/src/Compatibility/Core/src/Tizen/Forms.cs b/src/Compatibility/Core/src/Tizen/Forms.cs index be2a65eeff8a..37e729ca7310 100644 --- a/src/Compatibility/Core/src/Tizen/Forms.cs +++ b/src/Compatibility/Core/src/Tizen/Forms.cs @@ -103,7 +103,7 @@ public static class Forms public static Size PhysicalScreenSize => DeviceDisplay.MainDisplayInfo.GetScaledScreenSize(); - public static IReadOnlyList Flags => s_flags ?? (s_flags = new string[0]); + public static IReadOnlyList Flags => s_flags ?? (s_flags = Array.Empty()); public static IMauiContext MauiContext { get; internal set; } diff --git a/src/Compatibility/Core/src/iOS/DragAndDropDelegate.cs b/src/Compatibility/Core/src/iOS/DragAndDropDelegate.cs index 18985431364d..cef99f4afc67 100644 --- a/src/Compatibility/Core/src/iOS/DragAndDropDelegate.cs +++ b/src/Compatibility/Core/src/iOS/DragAndDropDelegate.cs @@ -34,7 +34,7 @@ public UIDragItem[] GetItemsForBeginningSession(UIDragInteraction interaction, I if (interaction.View is IVisualElementRenderer renderer && renderer.Element is View view) return HandleDragStarting(view, renderer); - return new UIDragItem[0]; + return Array.Empty(); } [Export("dropInteraction:canHandleSession:")] @@ -193,7 +193,7 @@ public UIDragItem[] HandleDragStarting(View element, IVisualElementRenderer rend }, element); - return returnValue ?? new UIDragItem[0]; + return returnValue ?? Array.Empty(); } void HandleDropCompleted(View element) diff --git a/src/Compatibility/Core/src/iOS/Extensions/DoubleCollectionExtensions.cs b/src/Compatibility/Core/src/iOS/Extensions/DoubleCollectionExtensions.cs index 093208f69df3..aefe312653ca 100644 --- a/src/Compatibility/Core/src/iOS/Extensions/DoubleCollectionExtensions.cs +++ b/src/Compatibility/Core/src/iOS/Extensions/DoubleCollectionExtensions.cs @@ -12,7 +12,7 @@ public static class DoubleCollectionExtensions public static nfloat[] ToArray(this DoubleCollection doubleCollection) { if (doubleCollection == null || doubleCollection.Count == 0) - return new nfloat[0]; + return Array.Empty(); else { diff --git a/src/Compatibility/Core/src/iOS/Extensions/PointCollectionExtensions.cs b/src/Compatibility/Core/src/iOS/Extensions/PointCollectionExtensions.cs index 294ca27da656..106d3747efeb 100644 --- a/src/Compatibility/Core/src/iOS/Extensions/PointCollectionExtensions.cs +++ b/src/Compatibility/Core/src/iOS/Extensions/PointCollectionExtensions.cs @@ -14,7 +14,7 @@ public static CGPoint[] ToCGPoints(this PointCollection pointCollection) { if (pointCollection == null || pointCollection.Count == 0) { - return new CGPoint[0]; + return System.Array.Empty(); } CGPoint[] points = new CGPoint[pointCollection.Count]; diff --git a/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs index f3850047fe3d..7eb2f18ec791 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs @@ -1422,8 +1422,8 @@ void UpdateToolbarItems() if (primaries != null) primaries.Reverse(); - NavigationItem.SetRightBarButtonItems(primaries == null ? new UIBarButtonItem[0] : primaries.ToArray(), false); - ToolbarItems = secondaries == null ? new UIBarButtonItem[0] : secondaries.ToArray(); + NavigationItem.SetRightBarButtonItems(primaries == null ? Array.Empty() : primaries.ToArray(), false); + ToolbarItems = secondaries == null ? Array.Empty() : secondaries.ToArray(); NavigationRenderer n; if (_navigation.TryGetTarget(out n)) diff --git a/src/Compatibility/Core/src/iOS/Renderers/WkWebViewRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/WkWebViewRenderer.cs index eae7b22ded8f..a9b50caa341b 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/WkWebViewRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/WkWebViewRenderer.cs @@ -358,7 +358,7 @@ async Task> GetCookiesFromNativeStore(string url) } } - _initialCookiesLoaded = _initialCookiesLoaded ?? new NSHttpCookie[0]; + _initialCookiesLoaded = _initialCookiesLoaded ?? Array.Empty(); List existingCookies = new List(); string domain = CreateUriForCookies(url).Host; diff --git a/src/Compatibility/Core/src/iOS/Shapes/ShapeRenderer.cs b/src/Compatibility/Core/src/iOS/Shapes/ShapeRenderer.cs index b598265ec8bd..d6c3a7b6bce3 100644 --- a/src/Compatibility/Core/src/iOS/Shapes/ShapeRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Shapes/ShapeRenderer.cs @@ -124,7 +124,7 @@ void UpdateStrokeThickness() void UpdateStrokeDashArray() { if (Element.StrokeDashArray == null || Element.StrokeDashArray.Count == 0) - Control.ShapeLayer.UpdateStrokeDash(new nfloat[0]); + Control.ShapeLayer.UpdateStrokeDash(Array.Empty()); else { nfloat[] dashArray; diff --git a/src/Controls/Foldable/src/DualScreenInfo.cs b/src/Controls/Foldable/src/DualScreenInfo.cs index 01d0da65f381..96ed6d4f8dec 100644 --- a/src/Controls/Foldable/src/DualScreenInfo.cs +++ b/src/Controls/Foldable/src/DualScreenInfo.cs @@ -69,7 +69,7 @@ public DualScreenInfo(VisualElement element) : this(element, null) internal DualScreenInfo(VisualElement element, IFoldableService dualScreenService) { - _spanningBounds = new Rect[0]; + _spanningBounds = Array.Empty(); Element = element; _dualScreenService = dualScreenService; @@ -179,10 +179,10 @@ Rect[] GetSpanningBounds() var hinge = guide.Hinge; if (hinge == Rect.Zero) - return new Rect[0]; + return Array.Empty(); if (guide.Pane2 == Rect.Zero) - return new Rect[0]; + return Array.Empty(); //TODO: I think this should this be checking SpanMode==Wide if (IsLandscape) diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CollectionModifier.cs b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CollectionModifier.cs index 0b0d82670aef..6e88537c4980 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CollectionModifier.cs +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/CollectionModifier.cs @@ -50,7 +50,7 @@ protected virtual bool ParseIndexes(out int[] indexes) { if (!int.TryParse(Entry.Text, out int index)) { - indexes = new int[0]; + indexes = Array.Empty(); return false; } diff --git a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs index f5198d5a2c5e..1cd68a14f0b9 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs @@ -1531,8 +1531,8 @@ void UpdateToolbarItems() if (primaries != null) primaries.Reverse(); - NavigationItem.SetRightBarButtonItems(primaries == null ? new UIBarButtonItem[0] : primaries.ToArray(), false); - ToolbarItems = secondaries == null ? new UIBarButtonItem[0] : secondaries.ToArray(); + NavigationItem.SetRightBarButtonItems(primaries == null ? Array.Empty() : primaries.ToArray(), false); + ToolbarItems = secondaries == null ? Array.Empty() : secondaries.ToArray(); NavigationRenderer n; if (_navigation.TryGetTarget(out n)) diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellItemRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellItemRenderer.cs index e1d147bc0369..528eaa84a495 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellItemRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellItemRenderer.cs @@ -14,6 +14,8 @@ namespace Microsoft.Maui.Controls.Platform.Compatibility { public class ShellItemRenderer : UITabBarController, IShellItemRenderer, IAppearanceObserver, IUINavigationControllerDelegate, IDisconnectable { + readonly static UITableViewCell[] EmptyUITableViewCellArray = Array.Empty(); + #region IShellItemRenderer public ShellItem ShellItem @@ -346,7 +348,7 @@ UITableViewCell[] GetMoreNavigationCells() if (MoreNavigationController.TopViewController.View is UITableView uITableView) return uITableView.VisibleCells; - return new UITableViewCell[0]; + return EmptyUITableViewCellArray; } } diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs index 778735694dd1..fc3f8dea72a5 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs @@ -302,7 +302,7 @@ protected virtual void UpdateToolbarItems() primaries.Reverse(); } - NavigationItem.SetRightBarButtonItems(primaries == null ? new UIBarButtonItem[0] : primaries.ToArray(), false); + NavigationItem.SetRightBarButtonItems(primaries == null ? Array.Empty() : primaries.ToArray(), false); UpdateLeftToolbarItems(); } diff --git a/src/Controls/src/Core/Handlers/Items/Android/Adapters/SelectableItemsViewAdapter.cs b/src/Controls/src/Core/Handlers/Items/Android/Adapters/SelectableItemsViewAdapter.cs index 2f94d8bf23c7..e01307722606 100644 --- a/src/Controls/src/Core/Handlers/Items/Android/Adapters/SelectableItemsViewAdapter.cs +++ b/src/Controls/src/Core/Handlers/Items/Android/Adapters/SelectableItemsViewAdapter.cs @@ -81,13 +81,13 @@ int[] GetSelectedPositions() switch (ItemsView.SelectionMode) { case SelectionMode.None: - return new int[0]; + return Array.Empty(); case SelectionMode.Single: var selectedItem = ItemsView.SelectedItem; if (selectedItem == null) { - return new int[0]; + return Array.Empty(); } return new int[1] { GetPositionForItem(selectedItem) }; @@ -104,7 +104,7 @@ int[] GetSelectedPositions() return result; } - return new int[0]; + return Array.Empty(); } bool PositionIsSelected(int position) diff --git a/src/Controls/src/Core/LegacyLayouts/ConstraintExpression.cs b/src/Controls/src/Core/LegacyLayouts/ConstraintExpression.cs index f29b1b93fb8f..a05780e21e70 100644 --- a/src/Controls/src/Core/LegacyLayouts/ConstraintExpression.cs +++ b/src/Controls/src/Core/LegacyLayouts/ConstraintExpression.cs @@ -40,7 +40,7 @@ public Constraint ProvideValue(IServiceProvider serviceProvider) if (string.IsNullOrEmpty(Property)) return null; minfo = typeof(View).GetProperties().First(pi => pi.Name == Property && pi.CanRead && pi.GetMethod.IsPublic).GetMethod; - return Constraint.RelativeToParent(p => (double)minfo.Invoke(p, new object[] { }) * Factor + Constant); + return Constraint.RelativeToParent(p => (double)minfo.Invoke(p, Array.Empty()) * Factor + Constant); case ConstraintType.Constant: return Constraint.Constant(Constant); case ConstraintType.RelativeToView: @@ -62,7 +62,7 @@ public Constraint ProvideValue(IServiceProvider serviceProvider) view = ((INameScope)valueProvider.TargetObject).FindByName(ElementName); } return Constraint.RelativeToView(view, delegate (RelativeLayout p, View v) - { return (double)minfo.Invoke(v, new object[] { }) * Factor + Constant; }); + { return (double)minfo.Invoke(v, Array.Empty()) * Factor + Constant; }); } } } diff --git a/src/Controls/src/Core/Menu/MenuItemTracker.cs b/src/Controls/src/Core/Menu/MenuItemTracker.cs index dcfa2c8c02ee..a6c614d086f3 100644 --- a/src/Controls/src/Core/Menu/MenuItemTracker.cs +++ b/src/Controls/src/Core/Menu/MenuItemTracker.cs @@ -52,7 +52,7 @@ public IList ToolbarItems get { if (Target == null) - return new TMenuItem[0]; + return Array.Empty(); // I realize this is sorting on every single get but we don't have // a mechanism in place currently to invalidate a stored version of this diff --git a/src/Controls/src/Core/Platform/iOS/DragAndDropDelegate.cs b/src/Controls/src/Core/Platform/iOS/DragAndDropDelegate.cs index 8adfd20b7b90..39ddc650ac34 100644 --- a/src/Controls/src/Core/Platform/iOS/DragAndDropDelegate.cs +++ b/src/Controls/src/Core/Platform/iOS/DragAndDropDelegate.cs @@ -231,7 +231,7 @@ public UIDragItem[] HandleDragStarting(View element, IPlatformViewHandler handle }, element); - return returnValue ?? new UIDragItem[0]; + return returnValue ?? Array.Empty(); } void SetLocalObject(UIDragItem dragItem, IPlatformViewHandler handler, DataPackage data) diff --git a/src/Controls/src/Core/Platform/iOS/Extensions/BrushExtensions.cs b/src/Controls/src/Core/Platform/iOS/Extensions/BrushExtensions.cs index 47a3bbc74062..a12f19761e8e 100644 --- a/src/Controls/src/Core/Platform/iOS/Extensions/BrushExtensions.cs +++ b/src/Controls/src/Core/Platform/iOS/Extensions/BrushExtensions.cs @@ -1,4 +1,5 @@ #nullable disable +using System; using System.Collections.Generic; using System.Linq; using CoreAnimation; @@ -222,7 +223,7 @@ static CGPoint GetRadialGradientBrushEndPoint(Point startPoint, double radius) static NSNumber[] GetCAGradientLayerLocations(List gradientStops) { if (gradientStops == null || gradientStops.Count == 0) - return new NSNumber[0]; + return Array.Empty(); if (gradientStops.Count > 1 && gradientStops.Any(gt => gt.Offset != 0)) return gradientStops.Select(x => new NSNumber(x.Offset)).ToArray(); @@ -254,7 +255,7 @@ static NSNumber[] GetCAGradientLayerLocations(List gradientStops) static CGColor[] GetCAGradientLayerColors(List gradientStops) { if (gradientStops == null || gradientStops.Count == 0) - return new CGColor[0]; + return Array.Empty(); CGColor[] colors = new CGColor[gradientStops.Count]; diff --git a/src/Controls/src/Core/PlatformBindingHelpers.cs b/src/Controls/src/Core/PlatformBindingHelpers.cs index dbee9c855456..a9f04355e5e6 100644 --- a/src/Controls/src/Core/PlatformBindingHelpers.cs +++ b/src/Controls/src/Core/PlatformBindingHelpers.cs @@ -90,7 +90,7 @@ static void SetValueFromNative(TPlatformView target, string targe BindableObjectProxy proxy; if (!BindableObjectProxy.BindableObjectProxies.TryGetValue(target, out proxy)) return; - SetValueFromRenderer(proxy, bindableProperty, target.GetType().GetProperty(targetProperty)?.GetMethod.Invoke(target, new object[] { })); + SetValueFromRenderer(proxy, bindableProperty, target.GetType().GetProperty(targetProperty)?.GetMethod.Invoke(target, Array.Empty())); } static void SetValueFromRenderer(BindableObject bindable, BindableProperty property, object value) diff --git a/src/Controls/src/Core/TemplatedItemsList.cs b/src/Controls/src/Core/TemplatedItemsList.cs index e49a827b73d5..bb5544bcec09 100644 --- a/src/Controls/src/Core/TemplatedItemsList.cs +++ b/src/Controls/src/Core/TemplatedItemsList.cs @@ -69,7 +69,7 @@ internal TemplatedItemsList(TView itemsView, BindableProperty itemSourceProperty if (source != null) ListProxy = new ListProxy(source, dispatcher: _itemsView.Dispatcher); else - ListProxy = new ListProxy(new object[0], dispatcher: _itemsView.Dispatcher); + ListProxy = new ListProxy(Array.Empty(), dispatcher: _itemsView.Dispatcher); } internal TemplatedItemsList(TemplatedItemsList parent, IEnumerable itemSource, TView itemsView, BindableProperty itemTemplateProperty, int windowSize = int.MaxValue) @@ -91,7 +91,7 @@ internal TemplatedItemsList(TemplatedItemsList parent, IEnumerable ListProxy.CollectionChanged += OnProxyCollectionChanged; } else - ListProxy = new ListProxy(new object[0], dispatcher: _itemsView.Dispatcher); + ListProxy = new ListProxy(Array.Empty(), dispatcher: _itemsView.Dispatcher); } event PropertyChangedEventHandler ITemplatedItemsList.PropertyChanged @@ -944,7 +944,7 @@ void OnItemsSourceChanged(bool fromGrouping = false) IEnumerable itemSource = GetItemsViewSource(); if (itemSource == null) - ListProxy = new ListProxy(new object[0], dispatcher: _itemsView.Dispatcher); + ListProxy = new ListProxy(Array.Empty(), dispatcher: _itemsView.Dispatcher); else ListProxy = new ListProxy(itemSource, dispatcher: _itemsView.Dispatcher); diff --git a/src/Controls/src/Xaml/ApplyPropertiesVisitor.cs b/src/Controls/src/Xaml/ApplyPropertiesVisitor.cs index 4137db0b83f9..5a5ab9321bd4 100644 --- a/src/Controls/src/Xaml/ApplyPropertiesVisitor.cs +++ b/src/Controls/src/Xaml/ApplyPropertiesVisitor.cs @@ -727,7 +727,7 @@ static bool TryGetProperty(object element, string localName, out object value, I if (!IsVisibleFrom(getter, rootElement)) return false; - value = getter.Invoke(element, new object[] { }); + value = getter.Invoke(element, Array.Empty()); return true; } diff --git a/src/Controls/src/Xaml/CreateValuesVisitor.cs b/src/Controls/src/Xaml/CreateValuesVisitor.cs index fb0f298f4d59..5eef0829d3bb 100644 --- a/src/Controls/src/Xaml/CreateValuesVisitor.cs +++ b/src/Controls/src/Xaml/CreateValuesVisitor.cs @@ -233,7 +233,7 @@ public object CreateFromFactory(Type nodeType, IElementNode node) } var factoryMethod = ((string)((ValueNode)node.Properties[XmlName.xFactoryMethod]).Value); - Type[] types = arguments == null ? new Type[0] : arguments.Select(a => a.GetType()).ToArray(); + Type[] types = arguments == null ? Array.Empty() : arguments.Select(a => a.GetType()).ToArray(); bool isMatch(MethodInfo m) { diff --git a/src/Controls/src/Xaml/MarkupExtensions/StaticExtension.cs b/src/Controls/src/Xaml/MarkupExtensions/StaticExtension.cs index 2c8101430eb8..ea1c7b8f6aa2 100644 --- a/src/Controls/src/Xaml/MarkupExtensions/StaticExtension.cs +++ b/src/Controls/src/Xaml/MarkupExtensions/StaticExtension.cs @@ -28,7 +28,7 @@ public object ProvideValue(IServiceProvider serviceProvider) var pinfo = type.GetRuntimeProperties().FirstOrDefault(pi => pi.Name == membername && pi.GetMethod.IsStatic); if (pinfo != null) - return pinfo.GetMethod.Invoke(null, new object[] { }); + return pinfo.GetMethod.Invoke(null, Array.Empty()); var finfo = type.GetRuntimeFields().FirstOrDefault(fi => fi.Name == membername && fi.IsStatic); if (finfo != null) diff --git a/src/Controls/tests/Core.UnitTests/BindableLayoutTests.cs b/src/Controls/tests/Core.UnitTests/BindableLayoutTests.cs index 9530f8239669..aba570e2896b 100644 --- a/src/Controls/tests/Core.UnitTests/BindableLayoutTests.cs +++ b/src/Controls/tests/Core.UnitTests/BindableLayoutTests.cs @@ -369,7 +369,7 @@ public void ValidateBindableProperties() // ItemsSourceProperty - IEnumerable itemsSource = new object[0]; + IEnumerable itemsSource = Array.Empty(); BindableLayout.SetItemsSource(layout, itemsSource); Assert.Equal(itemsSource, BindableLayout.GetItemsSource(layout)); diff --git a/src/Controls/tests/Core.UnitTests/BindingBaseUnitTests.cs b/src/Controls/tests/Core.UnitTests/BindingBaseUnitTests.cs index c3c1c7e8a557..a639edb2293a 100644 --- a/src/Controls/tests/Core.UnitTests/BindingBaseUnitTests.cs +++ b/src/Controls/tests/Core.UnitTests/BindingBaseUnitTests.cs @@ -696,9 +696,9 @@ public void EnableCollectionSynchronizationInvalid() { Assert.Throws(() => BindingBase.EnableCollectionSynchronization(null, new object(), (collection, context, method, access) => { })); - Assert.Throws(() => BindingBase.EnableCollectionSynchronization(new string[0], new object(), null)); + Assert.Throws(() => BindingBase.EnableCollectionSynchronization(Array.Empty(), new object(), null)); - BindingBase.EnableCollectionSynchronization(new string[0], null, (collection, context, method, access) => { }); + BindingBase.EnableCollectionSynchronization(Array.Empty(), null, (collection, context, method, access) => { }); } [Fact] diff --git a/src/Controls/tests/Core.UnitTests/DynamicBindingContextTests.cs b/src/Controls/tests/Core.UnitTests/DynamicBindingContextTests.cs index 35957f310d95..623bbd88d6a8 100644 --- a/src/Controls/tests/Core.UnitTests/DynamicBindingContextTests.cs +++ b/src/Controls/tests/Core.UnitTests/DynamicBindingContextTests.cs @@ -124,7 +124,7 @@ public override MethodInfo[] GetAccessors(bool nonPublic) public override ParameterInfo[] GetIndexParameters() { - return new ParameterInfo[0]; + return Array.Empty(); } public override object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, System.Globalization.CultureInfo culture) @@ -247,7 +247,7 @@ public override MethodImplAttributes GetMethodImplementationFlags() public override ParameterInfo[] GetParameters() { - return new ParameterInfo[0]; + return Array.Empty(); } public override RuntimeMethodHandle MethodHandle @@ -262,12 +262,12 @@ public override Type DeclaringType public override object[] GetCustomAttributes(Type attributeType, bool inherit) { - return new object[0]; + return Array.Empty(); } public override object[] GetCustomAttributes(bool inherit) { - return new object[0]; + return Array.Empty(); } public override bool IsDefined(Type attributeType, bool inherit) diff --git a/src/Controls/tests/Core.UnitTests/NotifiedPropertiesTests.cs b/src/Controls/tests/Core.UnitTests/NotifiedPropertiesTests.cs index 4ee4088e2c37..3f4208a35bfc 100644 --- a/src/Controls/tests/Core.UnitTests/NotifiedPropertiesTests.cs +++ b/src/Controls/tests/Core.UnitTests/NotifiedPropertiesTests.cs @@ -51,7 +51,7 @@ public override INotifyPropertyChanged CreateView() return init(); if (typeof(TView) == typeof(View)) return new View(); - return (TView)Activator.CreateInstance(typeof(TView), new object[] { }); + return (TView)Activator.CreateInstance(typeof(TView), Array.Empty()); } public override string DebugName diff --git a/src/Controls/tests/Core.UnitTests/TemplatedItemsListTests.cs b/src/Controls/tests/Core.UnitTests/TemplatedItemsListTests.cs index e29369101af8..de0c22ca6ddd 100644 --- a/src/Controls/tests/Core.UnitTests/TemplatedItemsListTests.cs +++ b/src/Controls/tests/Core.UnitTests/TemplatedItemsListTests.cs @@ -494,7 +494,7 @@ public void ItemsSourcePropertyChangedWithBindable() raised = true; }; - bindable.ItemsSource = new object[0]; + bindable.ItemsSource = Array.Empty(); Assert.True(raised, "INPC not raised for ItemsSource"); } diff --git a/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.iOS.cs b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.iOS.cs index 3d9b95fd8634..c5cd58ae4f49 100644 --- a/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.iOS.cs +++ b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.iOS.cs @@ -128,7 +128,7 @@ UIViewController[] GetActiveChildViewControllers(IElementHandler handler) handler = page.GetCurrentPage()?.Handler; if (handler is null) - return new UIViewController[0]; + return Array.Empty(); var navControllerResponder = (handler.PlatformView as UIView).FindResponder(); @@ -140,7 +140,7 @@ UIViewController[] GetActiveChildViewControllers(IElementHandler handler) if (contentResponder?.NavigationController is not null) return contentResponder.NavigationController.ChildViewControllers; - return new UIViewController[0]; + return Array.Empty(); } UIViewController GetVisibleViewController(IElementHandler handler) diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Gh4516.xaml.cs b/src/Controls/tests/Xaml.UnitTests/Issues/Gh4516.xaml.cs index 9f2c72b21ba5..82f8357a0291 100644 --- a/src/Controls/tests/Xaml.UnitTests/Issues/Gh4516.xaml.cs +++ b/src/Controls/tests/Xaml.UnitTests/Issues/Gh4516.xaml.cs @@ -8,7 +8,7 @@ namespace Microsoft.Maui.Controls.Xaml.UnitTests { public class Gh4516VM { - public Uri[] Images { get; } = { }; + public Uri[] Images { get; } = Array.Empty(); } public partial class Gh4516 : ContentPage diff --git a/src/Controls/tests/Xaml.UnitTests/NativeViewsAndBindings.xaml.cs b/src/Controls/tests/Xaml.UnitTests/NativeViewsAndBindings.xaml.cs index 9966946350fc..caee798a1c6b 100644 --- a/src/Controls/tests/Xaml.UnitTests/NativeViewsAndBindings.xaml.cs +++ b/src/Controls/tests/Xaml.UnitTests/NativeViewsAndBindings.xaml.cs @@ -73,7 +73,7 @@ public static void SetBinding(TNativeView target, string targetProp BindableProperty bindableProperty = null; propertyChanged ??= target as INotifyPropertyChanged; var propertyType = target.GetType().GetProperty(targetProperty)?.PropertyType; - var defaultValue = target.GetType().GetProperty(targetProperty)?.GetMethod.Invoke(target, new object[] { }); + var defaultValue = target.GetType().GetProperty(targetProperty)?.GetMethod.Invoke(target, Array.Empty()); bindableProperty = CreateBindableProperty(targetProperty, propertyType, defaultValue); if (binding != null && binding.Mode != BindingMode.OneWay && propertyChanged != null) propertyChanged.PropertyChanged += (sender, e) => @@ -123,7 +123,7 @@ static void SetValueFromNative(TNativeView target, string targetPro BindableObjectProxy proxy; if (!BindableObjectProxy.BindableObjectProxies.TryGetValue(target, out proxy)) return; - SetValueFromRenderer(proxy, bindableProperty, target.GetType().GetProperty(targetProperty)?.GetMethod.Invoke(target, new object[] { })); + SetValueFromRenderer(proxy, bindableProperty, target.GetType().GetProperty(targetProperty)?.GetMethod.Invoke(target, Array.Empty())); } static void SetValueFromRenderer(BindableObject bindable, BindableProperty property, object value) => bindable.SetValueCore(property, value); diff --git a/src/Core/src/.editorconfig b/src/Core/src/.editorconfig index 7dbbf925da8a..61762f96e25f 100644 --- a/src/Core/src/.editorconfig +++ b/src/Core/src/.editorconfig @@ -10,7 +10,6 @@ dotnet_diagnostic.CA1307.severity = error dotnet_diagnostic.CA1805.severity = error dotnet_diagnostic.CA1806.severity = error dotnet_diagnostic.CA1822.severity = error -dotnet_diagnostic.CA1825.severity = error dotnet_diagnostic.CA1834.severity = error dotnet_diagnostic.CA1845.severity = error dotnet_diagnostic.CA1846.severity = error diff --git a/src/Essentials/samples/Samples/Model/SampleItem.cs b/src/Essentials/samples/Samples/Model/SampleItem.cs index dba2867c10ed..46e433814435 100644 --- a/src/Essentials/samples/Samples/Model/SampleItem.cs +++ b/src/Essentials/samples/Samples/Model/SampleItem.cs @@ -10,7 +10,7 @@ public SampleItem(string icon, string name, Type pageType, string description, p Name = name; Description = description; PageType = pageType; - Tags = tags ?? new string[0]; + Tags = tags ?? Array.Empty(); } public string Icon { get; } diff --git a/src/Essentials/src/Sms/Sms.ios.cs b/src/Essentials/src/Sms/Sms.ios.cs index 832bfac830f6..f11e05dde1cf 100644 --- a/src/Essentials/src/Sms/Sms.ios.cs +++ b/src/Essentials/src/Sms/Sms.ios.cs @@ -1,6 +1,7 @@ -using System.Linq; using System.Threading.Tasks; #if !(MACCATALYST || MACOS) +using System; +using System.Linq; using MessageUI; #endif @@ -26,7 +27,7 @@ Task PlatformComposeAsync(SmsMessage message) if (!string.IsNullOrWhiteSpace(message?.Body)) messageController.Body = message.Body; - messageController.Recipients = message?.Recipients?.ToArray() ?? new string[] { }; + messageController.Recipients = message?.Recipients?.ToArray() ?? Array.Empty(); // show the controller var tcs = new TaskCompletionSource(); diff --git a/src/Essentials/src/VersionTracking/VersionTracking.shared.cs b/src/Essentials/src/VersionTracking/VersionTracking.shared.cs index 3dfa506dc001..c2a8dc5591ea 100644 --- a/src/Essentials/src/VersionTracking/VersionTracking.shared.cs +++ b/src/Essentials/src/VersionTracking/VersionTracking.shared.cs @@ -326,7 +326,7 @@ public string GetStatus() } string[] ReadHistory(string key) - => preferences.Get(key, null, sharedName)?.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) ?? new string[0]; + => preferences.Get(key, null, sharedName)?.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty(); void WriteHistory(string key, IEnumerable history) => preferences.Set(key, string.Join("|", history), sharedName); diff --git a/src/Graphics/src/Graphics/PathF.cs b/src/Graphics/src/Graphics/PathF.cs index 6247c2a41ce9..a8d9f690f629 100644 --- a/src/Graphics/src/Graphics/PathF.cs +++ b/src/Graphics/src/Graphics/PathF.cs @@ -666,7 +666,7 @@ public PointF[] GetPointsForSegment(int segmentIndex) { if (segment == segmentIndex) { - return new PointF[] { }; + return Array.Empty(); } } } diff --git a/src/Graphics/src/Graphics/Platforms/MaciOS/PlatformCanvas.cs b/src/Graphics/src/Graphics/Platforms/MaciOS/PlatformCanvas.cs index a0d20af12593..8b2245b9a820 100644 --- a/src/Graphics/src/Graphics/Platforms/MaciOS/PlatformCanvas.cs +++ b/src/Graphics/src/Graphics/Platforms/MaciOS/PlatformCanvas.cs @@ -15,7 +15,7 @@ namespace Microsoft.Maui.Graphics.Platform { public partial class PlatformCanvas : AbstractCanvas { - private static readonly nfloat[] EmptyNFloatArray = { }; + private static readonly nfloat[] EmptyNFloatArray = Array.Empty(); private static readonly CGAffineTransform FlipTransform = new CGAffineTransform(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f); private bool _antialias = true; diff --git a/src/Graphics/src/Graphics/Platforms/Windows/PlatformCanvasState.cs b/src/Graphics/src/Graphics/Platforms/Windows/PlatformCanvasState.cs index 67bbba4588b1..d06961c4d6a0 100644 --- a/src/Graphics/src/Graphics/Platforms/Windows/PlatformCanvasState.cs +++ b/src/Graphics/src/Graphics/Platforms/Windows/PlatformCanvasState.cs @@ -26,7 +26,7 @@ public class PlatformCanvasState #endif : CanvasState { - private static readonly float[] _emptyFloatArray = new float[] { }; + private static readonly float[] _emptyFloatArray = Array.Empty(); private readonly PlatformCanvas _owner; private readonly PlatformCanvasState _parentState; diff --git a/src/Graphics/src/Graphics/Platforms/iOS/UIViewExtensions.cs b/src/Graphics/src/Graphics/Platforms/iOS/UIViewExtensions.cs index d175eeee1e22..93c8bbbf5a7f 100644 --- a/src/Graphics/src/Graphics/Platforms/iOS/UIViewExtensions.cs +++ b/src/Graphics/src/Graphics/Platforms/iOS/UIViewExtensions.cs @@ -1,3 +1,4 @@ +using System; using Foundation; using UIKit; @@ -10,7 +11,7 @@ public static PointF[] GetPointsInView(this UIView target, UIEvent touchEvent) var touchSet = touchEvent.TouchesForView(target); if (touchSet.Count == 0) { - return new PointF[0]; + return Array.Empty(); } var touches = touchSet.ToArray();