From 637e6a971c5fb1ba53716ce2fc2adcb2959b055a Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Sat, 24 Feb 2024 19:10:36 -0600 Subject: [PATCH 1/8] chore: fix Xunit warnings --- tests/Prism.Core.Tests/Events/PubSubEventFixture.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Prism.Core.Tests/Events/PubSubEventFixture.cs b/tests/Prism.Core.Tests/Events/PubSubEventFixture.cs index 303fef6d61..d3888ba820 100644 --- a/tests/Prism.Core.Tests/Events/PubSubEventFixture.cs +++ b/tests/Prism.Core.Tests/Events/PubSubEventFixture.cs @@ -575,7 +575,7 @@ public void SubscribeDefaultsToPublisherThread() Action action = delegate { }; var token = PubSubEvent.Subscribe(action, true); - Assert.Equal(1, PubSubEvent.BaseSubscriptions.Count); + Assert.Single(PubSubEvent.BaseSubscriptions); Assert.Equal(typeof(EventSubscription), PubSubEvent.BaseSubscriptions.ElementAt(0).GetType()); } @@ -586,7 +586,7 @@ public void SubscribeDefaultsToPublisherThreadNonGeneric() Action action = delegate { }; var token = pubSubEvent.Subscribe(action, true); - Assert.Equal(1, pubSubEvent.BaseSubscriptions.Count); + Assert.Single(pubSubEvent.BaseSubscriptions); Assert.Equal(typeof(EventSubscription), pubSubEvent.BaseSubscriptions.ElementAt(0).GetType()); } From 2b9b78d33602580d4729b77839735005a13a45b5 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Sat, 24 Feb 2024 19:34:09 -0600 Subject: [PATCH 2/8] chore: resolving build warnings --- src/Maui/Prism.Maui/Dialogs/DialogService.cs | 20 +++++++++------ .../INavigationServiceExtensions.cs | 6 ++++- .../Behaviors/RegionActiveAwareBehavior.cs | 4 +-- .../Behaviors/RegionCreationException.cs | 13 +--------- .../RegionNavigationContentLoader.cs | 25 ++++++++----------- .../Mocks/ViewModels/MockViewModelBase.cs | 4 ++- .../Common}/ListDictionaryFixture.cs | 13 ++++------ 7 files changed, 38 insertions(+), 47 deletions(-) rename tests/{Wpf/Prism.Wpf.Tests => Prism.Core.Tests/Common}/ListDictionaryFixture.cs (95%) diff --git a/src/Maui/Prism.Maui/Dialogs/DialogService.cs b/src/Maui/Prism.Maui/Dialogs/DialogService.cs index 1d19984372..5034bb5007 100644 --- a/src/Maui/Prism.Maui/Dialogs/DialogService.cs +++ b/src/Maui/Prism.Maui/Dialogs/DialogService.cs @@ -1,9 +1,10 @@ using Prism.Commands; using Prism.Common; -using Prism.Ioc; -using Prism.Navigation; using Prism.Dialogs.Xaml; +using Prism.Mvvm; +using Prism.Navigation; +#nullable enable namespace Prism.Dialogs; /// @@ -22,8 +23,10 @@ public sealed class DialogService : IDialogService /// Throws when any constructor arguments are null. public DialogService(IContainerProvider container, IPageAccessor pageAccessor) { - _container = container ?? throw new ArgumentNullException(nameof(container)); - _pageAccessor = pageAccessor ?? throw new ArgumentNullException(nameof(pageAccessor)); + ArgumentNullException.ThrowIfNull(container); + ArgumentNullException.ThrowIfNull(pageAccessor); + _container = container; + _pageAccessor = pageAccessor; } /// @@ -37,7 +40,8 @@ public void ShowDialog(string name, IDialogParameters parameters, DialogCallback // This needs to be resolved when called as a Module could load any time // and register new dialogs var registry = _container.Resolve(); - var view = registry.CreateView(_container, UriParsingHelper.GetSegmentName(name)) as View; + var view = registry.CreateView(_container, UriParsingHelper.GetSegmentName(name)) as View + ?? throw new ViewCreationException(name, ViewType.Dialog); var currentPage = _pageAccessor.Page; dialogModal = _container.Resolve(); @@ -76,12 +80,12 @@ async Task DialogAware_RequestClose(IDialogResult outResult) if (dex.Message != DialogException.CanCloseIsFalse) { - await InvokeError(callback, dex, parameters); + await DialogService.InvokeError(callback, dex, parameters); } } catch (Exception ex) { - await InvokeError(callback, ex, parameters); + await DialogService.InvokeError(callback, ex, parameters); } finally { @@ -120,7 +124,7 @@ async Task DialogAware_RequestClose(IDialogResult outResult) } } - private async Task InvokeError(DialogCallback callback, Exception exception, IDialogParameters parameters) + private static async Task InvokeError(DialogCallback callback, Exception exception, IDialogParameters parameters) { var result = new DialogResult { diff --git a/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs b/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs index b38624fea9..89c472930f 100644 --- a/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs +++ b/src/Maui/Prism.Maui/Navigation/INavigationServiceExtensions.cs @@ -1,4 +1,4 @@ -using Prism.Common; +using Prism.Common; namespace Prism.Navigation; @@ -10,6 +10,7 @@ public static class INavigationServiceExtensions /// /// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack. /// + /// Service for handling navigation between views /// The name of the View to navigate back to /// indicating whether the request was successful or if there was an encountered . public static Task GoBackToAsync(this INavigationService navigationService, string name) => @@ -52,6 +53,7 @@ public static Task GoBackToRootAsync(this INavigationService /// /// Initiates navigation to the target specified by the . /// + /// Service for handling navigation between views /// The Uri to navigate to /// /// NavigateAsync(new Uri("MainPage?id=3&name=brian", UriKind.RelativeSource)); @@ -78,6 +80,7 @@ public static Task NavigateAsync(this INavigationService navi /// /// Initiates navigation to the target specified by the . /// + /// Service for handling navigation between views /// The name of the target to navigate to. public static Task NavigateAsync(this INavigationService navigationService, string name) => navigationService.NavigateAsync(name, default(INavigationParameters)); @@ -85,6 +88,7 @@ public static Task NavigateAsync(this INavigationService navi /// /// Initiates navigation to the target specified by the . /// + /// Service for handling navigation between views /// The name of the target to navigate to. /// The navigation parameters public static Task NavigateAsync(this INavigationService navigationService, string name, INavigationParameters parameters) diff --git a/src/Maui/Prism.Maui/Navigation/Regions/Behaviors/RegionActiveAwareBehavior.cs b/src/Maui/Prism.Maui/Navigation/Regions/Behaviors/RegionActiveAwareBehavior.cs index a61667e9b4..dd36ced1e2 100644 --- a/src/Maui/Prism.Maui/Navigation/Regions/Behaviors/RegionActiveAwareBehavior.cs +++ b/src/Maui/Prism.Maui/Navigation/Regions/Behaviors/RegionActiveAwareBehavior.cs @@ -1,4 +1,4 @@ -using System.Collections.Specialized; +using System.Collections.Specialized; using Prism.Common; namespace Prism.Navigation.Regions.Behaviors; @@ -11,7 +11,7 @@ namespace Prism.Navigation.Regions.Behaviors; /// /// /// This class can also sync the active state for any scoped regions directly on the view based on the . -/// If you use the method with the createRegionManagerScope option, the scoped manager will be attached to the view. +/// If you use the method with the createRegionManagerScope option, the scoped manager will be attached to the view. /// public class RegionActiveAwareBehavior : IRegionBehavior { diff --git a/src/Maui/Prism.Maui/Navigation/Regions/Behaviors/RegionCreationException.cs b/src/Maui/Prism.Maui/Navigation/Regions/Behaviors/RegionCreationException.cs index 54c0c3e0ee..240e957cdc 100644 --- a/src/Maui/Prism.Maui/Navigation/Regions/Behaviors/RegionCreationException.cs +++ b/src/Maui/Prism.Maui/Navigation/Regions/Behaviors/RegionCreationException.cs @@ -1,11 +1,10 @@ -using System.Runtime.Serialization; +using System.Runtime.Serialization; namespace Prism.Navigation.Regions.Behaviors; /// /// Represents errors that occurred during region creation. /// -[Serializable] public partial class RegionCreationException : Exception { /// @@ -35,14 +34,4 @@ public RegionCreationException(string message, Exception inner) : base(message, inner) { } - - /// - /// Initializes a new instance of the class with serialized data. - /// - /// The that holds the serialized object data about the exception being thrown. - /// The that contains contextual information about the source or destination. - protected RegionCreationException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } diff --git a/src/Maui/Prism.Maui/Navigation/Regions/Navigation/RegionNavigationContentLoader.cs b/src/Maui/Prism.Maui/Navigation/Regions/Navigation/RegionNavigationContentLoader.cs index 8940098965..c78063dce9 100644 --- a/src/Maui/Prism.Maui/Navigation/Regions/Navigation/RegionNavigationContentLoader.cs +++ b/src/Maui/Prism.Maui/Navigation/Regions/Navigation/RegionNavigationContentLoader.cs @@ -1,4 +1,4 @@ -using System.Globalization; +using System.Globalization; using Prism.Common; using Prism.Ioc; using Prism.Mvvm; @@ -27,11 +27,8 @@ public class RegionNavigationContentLoader : IRegionNavigationContentLoader /// when a new view cannot be created for the navigation request. public object LoadContent(IRegion region, NavigationContext navigationContext) { - if (region == null) - throw new ArgumentNullException(nameof(region)); - - if (navigationContext == null) - throw new ArgumentNullException(nameof(navigationContext)); + ArgumentNullException.ThrowIfNull(region); + ArgumentNullException.ThrowIfNull(navigationContext); string candidateTargetContract = GetContractFromNavigationContext(navigationContext); @@ -58,6 +55,7 @@ public object LoadContent(IRegion region, NavigationContext navigationContext) /// Provides a new item for the region based on the supplied candidate target contract name. /// /// The target contract to build. + /// The to create the new Region Item in. /// An instance of an item to put into the . protected virtual object CreateNewRegionItem(string candidateTargetContract, IRegion region) { @@ -89,7 +87,7 @@ protected virtual object CreateNewRegionItem(string candidateTargetContract, IRe /// The candidate contract to seek within the and to use, if not found, when resolving from the container. protected virtual string GetContractFromNavigationContext(NavigationContext navigationContext) { - if (navigationContext == null) throw new ArgumentNullException(nameof(navigationContext)); + ArgumentNullException.ThrowIfNull(navigationContext); var candidateTargetContract = UriParsingHelper.EnsureAbsolute(navigationContext.Uri).AbsolutePath; candidateTargetContract = candidateTargetContract.TrimStart('/'); @@ -104,17 +102,14 @@ protected virtual string GetContractFromNavigationContext(NavigationContext navi /// An enumerable of candidate objects from the protected virtual IEnumerable GetCandidatesFromRegion(IRegion region, string candidateNavigationContract) { - if (region is null) - { - throw new ArgumentNullException(nameof(region)); - } + ArgumentNullException.ThrowIfNull(region); if (string.IsNullOrEmpty(candidateNavigationContract)) { throw new ArgumentNullException(nameof(candidateNavigationContract)); } - var contractCandidates = GetCandidatesFromRegionViews(region, candidateNavigationContract); + var contractCandidates = RegionNavigationContentLoader.GetCandidatesFromRegionViews(region, candidateNavigationContract); if (!contractCandidates.Any()) { @@ -122,16 +117,16 @@ protected virtual IEnumerable GetCandidatesFromRegion(IRegion reg var registration = registry.Registrations.FirstOrDefault(x => x.Type == ViewType.Region && (x.Name == candidateNavigationContract || x.View.Name == candidateNavigationContract || x.View.FullName == candidateNavigationContract)); if (registration is null) { - GetCandidatesFromRegionViews(region, registration.View.FullName); + RegionNavigationContentLoader.GetCandidatesFromRegionViews(region, registration.View.FullName); } - return Array.Empty(); + return []; } return contractCandidates; } - private IEnumerable GetCandidatesFromRegionViews(IRegion region, string candidateNavigationContract) + private static IEnumerable GetCandidatesFromRegionViews(IRegion region, string candidateNavigationContract) { return region.Views.OfType().Where(v => ViewIsMatch(v.GetType(), candidateNavigationContract)); } diff --git a/tests/Maui/Prism.DryIoc.Maui.Tests/Mocks/ViewModels/MockViewModelBase.cs b/tests/Maui/Prism.DryIoc.Maui.Tests/Mocks/ViewModels/MockViewModelBase.cs index f5c8a69f5f..e03e872c68 100644 --- a/tests/Maui/Prism.DryIoc.Maui.Tests/Mocks/ViewModels/MockViewModelBase.cs +++ b/tests/Maui/Prism.DryIoc.Maui.Tests/Mocks/ViewModels/MockViewModelBase.cs @@ -1,7 +1,8 @@ -using Prism.Common; +using Prism.Common; namespace Prism.DryIoc.Maui.Tests.Mocks.ViewModels; +#pragma warning disable CS0067 // The event is never used because this is a Mock public abstract class MockViewModelBase : IActiveAware, INavigationAware, IConfirmNavigation { private readonly IPageAccessor _pageAccessor; @@ -49,3 +50,4 @@ public void OnNavigatedTo(INavigationParameters parameters) Message = message; } } +#pragma warning restore CS0067 // The event is never used because this is a Mock diff --git a/tests/Wpf/Prism.Wpf.Tests/ListDictionaryFixture.cs b/tests/Prism.Core.Tests/Common/ListDictionaryFixture.cs similarity index 95% rename from tests/Wpf/Prism.Wpf.Tests/ListDictionaryFixture.cs rename to tests/Prism.Core.Tests/Common/ListDictionaryFixture.cs index a458057d26..eb25cc801e 100644 --- a/tests/Wpf/Prism.Wpf.Tests/ListDictionaryFixture.cs +++ b/tests/Prism.Core.Tests/Common/ListDictionaryFixture.cs @@ -1,5 +1,3 @@ - - using System; using System.Collections.Generic; using Prism.Common; @@ -78,7 +76,7 @@ public void CanRemoveValue() list.Add("foo", value); list.RemoveValue("foo", value); - Assert.Equal(0, list["foo"].Count); + Assert.Empty(list["foo"]); } [Fact] @@ -90,7 +88,7 @@ public void CanRemoveValueFromAllLists() list.RemoveValue(value); - Assert.Equal(0, list.Values.Count); + Assert.Empty(list.Values); } [Fact] @@ -125,20 +123,19 @@ public void CanRemoveList() bool removed = list.Remove("foo"); Assert.True(removed); - Assert.Equal(0, list.Keys.Count); + Assert.Empty(list.Keys); } [Fact] public void CanSetList() { - List values = new List(); - values.Add(new object()); + List values = [new object()]; list.Add("foo", new object()); list.Add("foo", new object()); list["foo"] = values; - Assert.Equal(1, list["foo"].Count); + Assert.Single(list["foo"]); } [Fact] From ca99d9df7ddb04ebf7b2b8372f306531f8cd1bc9 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Sat, 24 Feb 2024 20:05:34 -0600 Subject: [PATCH 3/8] chore: use global namespaces for WPF/Uno Platform types --- Directory.Build.props | 27 ++++++++++++++++--- src/Wpf/Prism.Wpf/Common/MvvmHelpers.cs | 5 ---- src/Wpf/Prism.Wpf/Common/ObservableObject.cs | 8 ------ src/Wpf/Prism.Wpf/Dialogs/Dialog.cs | 6 ----- .../Extensions/DependencyObjectExtensions.cs | 8 ------ .../Interactivity/CommandBehaviorBase.cs | 8 ------ ...RegionContextToDependencyObjectBehavior.cs | 6 ----- .../ClearChildViewsRegionBehavior.cs | 6 ----- .../DelayedRegionCreationBehavior.cs | 6 ----- .../Behaviors/IHostAwareRegionBehavior.cs | 6 +---- .../Behaviors/RegionActiveAwareBehavior.cs | 6 ----- .../RegionManagerRegistrationBehavior.cs | 7 ----- .../Behaviors/RegionMemberLifetimeBehavior.cs | 6 ----- .../SelectorItemsSourceSyncBehavior.cs | 12 --------- .../SyncRegionContextWithHostBehavior.cs | 6 ----- .../Regions/ContentControlRegionAdapter.cs | 9 ------- .../Regions/DefaultRegionManagerAccessor.cs | 6 ----- .../Regions/IRegionManagerAccessor.cs | 6 ----- .../Navigation/Regions/ItemMetadata.cs | 6 ----- .../Regions/ItemsControlRegionAdapter.cs | 10 ------- .../Prism.Wpf/Navigation/Regions/Region.cs | 10 ------- .../Navigation/Regions/RegionAdapterBase.cs | 7 ----- .../Navigation/Regions/RegionContext.cs | 6 ----- .../Navigation/Regions/RegionManager.cs | 7 ----- .../Regions/RegionNavigationContentLoader.cs | 7 ----- .../Regions/RegionNavigationService.cs | 6 ----- .../Regions/SelectorRegionAdapter.cs | 6 ----- .../PrismInitializationExtensions.cs | 8 ------ .../Mocks/DependantA.cs | 3 --- .../Mocks/DependantB.cs | 3 --- 30 files changed, 25 insertions(+), 198 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 1ee16833a4..b6cf57ec0f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -54,9 +54,30 @@ 3.0.44 - - $(DefineConstants);UNO_WINUI_PROJECT - + + + + + + + + + + + + + $(DefineConstants);UNO_WINUI_PROJECT + + + + + + + + + + diff --git a/src/Wpf/Prism.Wpf/Common/MvvmHelpers.cs b/src/Wpf/Prism.Wpf/Common/MvvmHelpers.cs index 86583922ec..f6a6d2de21 100644 --- a/src/Wpf/Prism.Wpf/Common/MvvmHelpers.cs +++ b/src/Wpf/Prism.Wpf/Common/MvvmHelpers.cs @@ -3,11 +3,6 @@ using System.ComponentModel; using System.Linq; using Prism.Mvvm; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif namespace Prism.Common { diff --git a/src/Wpf/Prism.Wpf/Common/ObservableObject.cs b/src/Wpf/Prism.Wpf/Common/ObservableObject.cs index 42086f1fd5..03dc613042 100644 --- a/src/Wpf/Prism.Wpf/Common/ObservableObject.cs +++ b/src/Wpf/Prism.Wpf/Common/ObservableObject.cs @@ -1,13 +1,5 @@ - - using System.ComponentModel; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Common { /// diff --git a/src/Wpf/Prism.Wpf/Dialogs/Dialog.cs b/src/Wpf/Prism.Wpf/Dialogs/Dialog.cs index b25fac0964..c7896dba82 100644 --- a/src/Wpf/Prism.Wpf/Dialogs/Dialog.cs +++ b/src/Wpf/Prism.Wpf/Dialogs/Dialog.cs @@ -1,9 +1,3 @@ -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Dialogs { /// diff --git a/src/Wpf/Prism.Wpf/Extensions/DependencyObjectExtensions.cs b/src/Wpf/Prism.Wpf/Extensions/DependencyObjectExtensions.cs index e6c63dc09d..2d40fe8f87 100644 --- a/src/Wpf/Prism.Wpf/Extensions/DependencyObjectExtensions.cs +++ b/src/Wpf/Prism.Wpf/Extensions/DependencyObjectExtensions.cs @@ -2,14 +2,6 @@ using System.Collections.Generic; using System.Text; -#if HAS_WINUI -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Data; -#else -using System.Windows; -using System.Windows.Data; -#endif - namespace Prism { internal static partial class DependencyObjectExtensions diff --git a/src/Wpf/Prism.Wpf/Interactivity/CommandBehaviorBase.cs b/src/Wpf/Prism.Wpf/Interactivity/CommandBehaviorBase.cs index d7063d1f6e..3483e7149a 100644 --- a/src/Wpf/Prism.Wpf/Interactivity/CommandBehaviorBase.cs +++ b/src/Wpf/Prism.Wpf/Interactivity/CommandBehaviorBase.cs @@ -1,14 +1,6 @@ using System; using System.Windows.Input; -#if HAS_WINUI -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -#else -using System.Windows; -using System.Windows.Controls; -#endif - namespace Prism.Interactivity { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/BindRegionContextToDependencyObjectBehavior.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/BindRegionContextToDependencyObjectBehavior.cs index a90ddde8fb..6c4d2c6f09 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/BindRegionContextToDependencyObjectBehavior.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/BindRegionContextToDependencyObjectBehavior.cs @@ -3,12 +3,6 @@ using System.Collections.Specialized; using System.ComponentModel; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions.Behaviors { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/ClearChildViewsRegionBehavior.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/ClearChildViewsRegionBehavior.cs index 040a4701d2..6e050dae65 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/ClearChildViewsRegionBehavior.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/ClearChildViewsRegionBehavior.cs @@ -1,11 +1,5 @@ using System; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions.Behaviors { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/DelayedRegionCreationBehavior.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/DelayedRegionCreationBehavior.cs index 85ce900f92..b07efddb93 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/DelayedRegionCreationBehavior.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/DelayedRegionCreationBehavior.cs @@ -4,12 +4,6 @@ using System.Collections.ObjectModel; using System.Globalization; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions.Behaviors { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/IHostAwareRegionBehavior.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/IHostAwareRegionBehavior.cs index ee303ac768..02ddf35081 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/IHostAwareRegionBehavior.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/IHostAwareRegionBehavior.cs @@ -1,8 +1,4 @@ -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif + namespace Prism.Navigation.Regions.Behaviors { diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionActiveAwareBehavior.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionActiveAwareBehavior.cs index dc9866dab9..fda0162215 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionActiveAwareBehavior.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionActiveAwareBehavior.cs @@ -3,12 +3,6 @@ using System.Linq; using Prism.Common; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions.Behaviors { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionManagerRegistrationBehavior.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionManagerRegistrationBehavior.cs index 0f42de884a..a952b77e55 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionManagerRegistrationBehavior.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionManagerRegistrationBehavior.cs @@ -2,13 +2,6 @@ using System.ComponentModel; using Prism.Properties; -#if HAS_WINUI -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Media; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions.Behaviors { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionMemberLifetimeBehavior.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionMemberLifetimeBehavior.cs index 3047a22e3b..3b19146484 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionMemberLifetimeBehavior.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/RegionMemberLifetimeBehavior.cs @@ -4,12 +4,6 @@ using System.Collections.Specialized; using Prism.Common; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions.Behaviors { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/SelectorItemsSourceSyncBehavior.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/SelectorItemsSourceSyncBehavior.cs index 9654e5bf68..96f76fbff3 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/SelectorItemsSourceSyncBehavior.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/SelectorItemsSourceSyncBehavior.cs @@ -3,18 +3,6 @@ using System.Collections.Specialized; using Prism.Properties; -#if HAS_WINUI -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Controls.Primitives; -using Microsoft.UI.Xaml.Data; -#else -using System.Windows; -using System.Windows.Controls; -using System.Windows.Controls.Primitives; -using System.Windows.Data; -#endif - namespace Prism.Navigation.Regions.Behaviors { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/SyncRegionContextWithHostBehavior.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/SyncRegionContextWithHostBehavior.cs index e545d5cfa3..4d978e3c7f 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/SyncRegionContextWithHostBehavior.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/SyncRegionContextWithHostBehavior.cs @@ -2,12 +2,6 @@ using Prism.Properties; using Prism.Common; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions.Behaviors { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/ContentControlRegionAdapter.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/ContentControlRegionAdapter.cs index 02d928ad6e..ff98e837e0 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/ContentControlRegionAdapter.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/ContentControlRegionAdapter.cs @@ -3,15 +3,6 @@ using System.Collections.Specialized; using System.Linq; -#if HAS_WINUI -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Data; -#else -using System.Windows.Controls; -using System.Windows.Data; -#endif - namespace Prism.Navigation.Regions { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/DefaultRegionManagerAccessor.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/DefaultRegionManagerAccessor.cs index cf08bff621..9187c37832 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/DefaultRegionManagerAccessor.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/DefaultRegionManagerAccessor.cs @@ -1,11 +1,5 @@ using System; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions { internal class DefaultRegionManagerAccessor : IRegionManagerAccessor diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/IRegionManagerAccessor.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/IRegionManagerAccessor.cs index 185e30bed2..bf5af77bcb 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/IRegionManagerAccessor.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/IRegionManagerAccessor.cs @@ -1,11 +1,5 @@ using System; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/ItemMetadata.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/ItemMetadata.cs index 721149db72..a213a3a810 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/ItemMetadata.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/ItemMetadata.cs @@ -1,11 +1,5 @@ using System; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/ItemsControlRegionAdapter.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/ItemsControlRegionAdapter.cs index b7c08a32d8..122fedc62b 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/ItemsControlRegionAdapter.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/ItemsControlRegionAdapter.cs @@ -1,16 +1,6 @@ using Prism.Properties; using System; -#if HAS_WINUI -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Data; -#else -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -#endif - namespace Prism.Navigation.Regions { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs index f843dbdc3d..959db90af7 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs @@ -6,16 +6,6 @@ using Prism.Properties; using Prism.Ioc; -#if HAS_WINUI -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Data; -#else -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -#endif - namespace Prism.Navigation.Regions { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionAdapterBase.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionAdapterBase.cs index 588c6755dc..073701a613 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionAdapterBase.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionAdapterBase.cs @@ -3,13 +3,6 @@ using System; using System.Globalization; -#if HAS_WINUI -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Data; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionContext.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionContext.cs index 48d61b405e..6ddab3df10 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionContext.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionContext.cs @@ -1,12 +1,6 @@ using Prism.Common; using System; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionManager.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionManager.cs index 3b2e7b7b94..327ef18fb6 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionManager.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionManager.cs @@ -14,13 +14,6 @@ using Prism.Navigation.Regions.Behaviors; using Prism.Ioc.Internals; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - - namespace Prism.Navigation.Regions { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationContentLoader.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationContentLoader.cs index 65e17c545d..2124f76637 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationContentLoader.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationContentLoader.cs @@ -7,13 +7,6 @@ using Prism.Ioc.Internals; using Prism.Properties; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - - namespace Prism.Navigation.Regions { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationService.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationService.cs index 069cd710eb..220a9a7a65 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationService.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionNavigationService.cs @@ -6,12 +6,6 @@ using Prism.Properties; using Prism.Ioc; -#if HAS_WINUI -using Microsoft.UI.Xaml; -#else -using System.Windows; -#endif - namespace Prism.Navigation.Regions { /// diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/SelectorRegionAdapter.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/SelectorRegionAdapter.cs index 9aa545cccf..ce434aa899 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/SelectorRegionAdapter.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/SelectorRegionAdapter.cs @@ -1,12 +1,6 @@ using Prism.Navigation.Regions.Behaviors; using System; -#if HAS_WINUI -using Microsoft.UI.Xaml.Controls.Primitives; -#else -using System.Windows.Controls.Primitives; -#endif - namespace Prism.Navigation.Regions { /// diff --git a/src/Wpf/Prism.Wpf/PrismInitializationExtensions.cs b/src/Wpf/Prism.Wpf/PrismInitializationExtensions.cs index 4b9c54b074..809566d076 100644 --- a/src/Wpf/Prism.Wpf/PrismInitializationExtensions.cs +++ b/src/Wpf/Prism.Wpf/PrismInitializationExtensions.cs @@ -6,14 +6,6 @@ using Prism.Navigation.Regions.Behaviors; using Prism.Dialogs; -#if HAS_WINUI -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Controls.Primitives; -#else -using System.Windows.Controls; -using System.Windows.Controls.Primitives; -#endif - namespace Prism { internal static class PrismInitializationExtensions diff --git a/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/DependantA.cs b/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/DependantA.cs index 0a939832b7..21a15134b6 100644 --- a/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/DependantA.cs +++ b/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/DependantA.cs @@ -1,6 +1,3 @@ - - - namespace Prism.IocContainer.Wpf.Tests.Support.Mocks { public class DependantA : IDependantA diff --git a/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/DependantB.cs b/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/DependantB.cs index b7ab342aed..c962b09d06 100644 --- a/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/DependantB.cs +++ b/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/DependantB.cs @@ -1,6 +1,3 @@ - - - namespace Prism.IocContainer.Wpf.Tests.Support.Mocks { public class DependantB : IDependantB From 5e08bcdbaac71def4cc603fb4727daa887898b60 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Sat, 24 Feb 2024 20:17:52 -0600 Subject: [PATCH 4/8] chore: use nameof --- src/Wpf/Prism.Wpf/Common/ObservableObject.cs | 2 +- src/Wpf/Prism.Wpf/Interactivity/InvokeCommandAction.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Wpf/Prism.Wpf/Common/ObservableObject.cs b/src/Wpf/Prism.Wpf/Common/ObservableObject.cs index 03dc613042..465c66aea6 100644 --- a/src/Wpf/Prism.Wpf/Common/ObservableObject.cs +++ b/src/Wpf/Prism.Wpf/Common/ObservableObject.cs @@ -17,7 +17,7 @@ public partial class ObservableObject : FrameworkElement, INotifyPropertyChan /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "This is the pattern for WPF dependency properties")] public static readonly DependencyProperty ValueProperty = - DependencyProperty.Register("Value", typeof(T), typeof(ObservableObject), new PropertyMetadata(null, ValueChangedCallback)); + DependencyProperty.Register(nameof(Value), typeof(T), typeof(ObservableObject), new PropertyMetadata(null, ValueChangedCallback)); /// /// Event that gets invoked when the Value property changes. diff --git a/src/Wpf/Prism.Wpf/Interactivity/InvokeCommandAction.cs b/src/Wpf/Prism.Wpf/Interactivity/InvokeCommandAction.cs index 8dd23c57d7..2063204d90 100644 --- a/src/Wpf/Prism.Wpf/Interactivity/InvokeCommandAction.cs +++ b/src/Wpf/Prism.Wpf/Interactivity/InvokeCommandAction.cs @@ -17,7 +17,7 @@ public class InvokeCommandAction : TriggerAction /// Dependency property identifying if the associated element should automatically be enabled or disabled based on the result of the Command's CanExecute /// public static readonly DependencyProperty AutoEnableProperty = - DependencyProperty.Register("AutoEnable", typeof(bool), typeof(InvokeCommandAction), + DependencyProperty.Register(nameof(AutoEnable), typeof(bool), typeof(InvokeCommandAction), new PropertyMetadata(true, (d, e) => ((InvokeCommandAction)d).OnAllowDisableChanged((bool)e.NewValue))); /// @@ -40,7 +40,7 @@ private void OnAllowDisableChanged(bool newValue) /// Dependency property identifying the command to execute when invoked. /// public static readonly DependencyProperty CommandProperty = - DependencyProperty.Register("Command", typeof(ICommand), typeof(InvokeCommandAction), + DependencyProperty.Register(nameof(Command), typeof(ICommand), typeof(InvokeCommandAction), new PropertyMetadata(null, (d, e) => ((InvokeCommandAction)d).OnCommandChanged((ICommand)e.NewValue))); /// @@ -63,7 +63,7 @@ private void OnCommandChanged(ICommand newValue) /// Dependency property identifying the command parameter to supply on command execution. /// public static readonly DependencyProperty CommandParameterProperty = - DependencyProperty.Register("CommandParameter", typeof(object), typeof(InvokeCommandAction), + DependencyProperty.Register(nameof(CommandParameter), typeof(object), typeof(InvokeCommandAction), new PropertyMetadata(null, (d, e) => ((InvokeCommandAction)d).OnCommandParameterChanged(e.NewValue))); /// @@ -86,7 +86,7 @@ private void OnCommandParameterChanged(object newValue) /// Dependency property identifying the TriggerParameterPath to be parsed to identify the child property of the trigger parameter to be used as the command parameter. /// public static readonly DependencyProperty TriggerParameterPathProperty = - DependencyProperty.Register("TriggerParameterPath", typeof(string), typeof(InvokeCommandAction), + DependencyProperty.Register(nameof(TriggerParameterPath), typeof(string), typeof(InvokeCommandAction), new PropertyMetadata(null, (d, e) => { })); /// From e7a839fa2441cd40030e69d8aa977689d06dc676 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Sat, 24 Feb 2024 20:18:46 -0600 Subject: [PATCH 5/8] chore: update editorconfig --- .editorconfig | 117 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 7 deletions(-) diff --git a/.editorconfig b/.editorconfig index 1d25ab7aa0..b947be645f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,14 +10,22 @@ root = true [*] indent_style = space -end_of_line = CRLF +end_of_line = crlf trim_trailing_whitespace = true insert_final_newline = true +charset = utf-8 ########################################## # File Extension Settings ########################################## +[*.{yml,yaml}] +indent_size = 2 + +[.vsconfig] +indent_size = 2 +end_of_line = lf + [*.sln] indent_style = tab indent_size = 2 @@ -25,40 +33,135 @@ indent_size = 2 [*.{csproj,proj,projitems,shproj}] indent_size = 2 -[*.json] +[*.{json,slnf}] indent_size = 2 +end_of_line = lf [*.{props,targets}] indent_size = 2 -[*.targets] +[*.xaml] indent_size = 2 +charset = utf-8-bom -[*.xaml] +[*.xml] indent_size = 2 +end_of_line = lf [*.plist] indent_size = 2 indent_style = tab +end_of_line = lf + +[*.manifest] +indent_size = 2 + +[*.appxmanifest] +indent_size = 2 + +[*.{json,css,webmanifest}] +indent_size = 2 +end_of_line = lf + +[web.config] +indent_size = 2 +end_of_line = lf [*.sh] indent_size = 2 end_of_line = lf [*.cs] +# EOL should be normalized by Git. See https://github.com/dotnet/format/issues/1099 +end_of_line = unset + +# See https://github.com/dotnet/roslyn/issues/20356#issuecomment-310143926 +trim_trailing_whitespace = false + +tab_width = 4 indent_size = 4 # Sort using and Import directives with System.* appearing first dotnet_sort_system_directives_first = true + # Avoid "this." and "Me." if not necessary dotnet_style_qualification_for_field = false:suggestion dotnet_style_qualification_for_property = false:suggestion dotnet_style_qualification_for_method = false:suggestion dotnet_style_qualification_for_event = false:suggestion -# Suggest more modern language features when available -dotnet_style_object_initializer = true:suggestion -dotnet_style_collection_initializer = true:suggestion +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case +dotnet_style_operator_placement_when_wrapping = beginning_of_line dotnet_style_coalesce_expression = true:suggestion dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion + +csharp_indent_labels = one_less_than_current +csharp_using_directive_placement = outside_namespace:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_prefer_braces = true:silent +csharp_style_namespace_declarations = file_scoped:warning +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_prefer_primary_constructors = true:suggestion +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent From 08e27a911c981403725ba842037471405ab7003a Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Sat, 24 Feb 2024 20:20:55 -0600 Subject: [PATCH 6/8] chore: simplify code --- src/Wpf/Prism.Wpf/Common/ObservableObject.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Wpf/Prism.Wpf/Common/ObservableObject.cs b/src/Wpf/Prism.Wpf/Common/ObservableObject.cs index 465c66aea6..6a49185b29 100644 --- a/src/Wpf/Prism.Wpf/Common/ObservableObject.cs +++ b/src/Wpf/Prism.Wpf/Common/ObservableObject.cs @@ -30,18 +30,14 @@ public partial class ObservableObject : FrameworkElement, INotifyPropertyChan [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")] public T Value { - get { return (T)this.GetValue(ValueProperty); } - set { this.SetValue(ValueProperty, value); } + get => (T)GetValue(ValueProperty); + set => SetValue(ValueProperty, value); } private static void ValueChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { ObservableObject thisInstance = ((ObservableObject)d); - PropertyChangedEventHandler eventHandler = thisInstance.PropertyChanged; - if (eventHandler != null) - { - eventHandler(thisInstance, new PropertyChangedEventArgs("Value")); - } + thisInstance.PropertyChanged?.Invoke(thisInstance, new PropertyChangedEventArgs(nameof(Value))); } } } From c984d4a63b5bc1f29c07edd7b18180a92837f6b7 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Sat, 24 Feb 2024 20:34:50 -0600 Subject: [PATCH 7/8] chore: adding WPF compatibility APIs --- src/Uno/Prism.Uno/Common/BindingOperations.cs | 7 +++++++ src/Uno/Prism.Uno/Common/DesignerProperties.cs | 7 +++++++ src/Wpf/Prism.Wpf/Common/MvvmHelpers.cs | 4 ++-- .../Prism.Wpf/Extensions/DependencyObjectExtensions.cs | 8 ++------ src/Wpf/Prism.Wpf/Mvvm/ViewModelLocator.cs | 2 -- src/Wpf/Prism.Wpf/Navigation/Regions/RegionManager.cs | 4 ---- 6 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 src/Uno/Prism.Uno/Common/BindingOperations.cs create mode 100644 src/Uno/Prism.Uno/Common/DesignerProperties.cs diff --git a/src/Uno/Prism.Uno/Common/BindingOperations.cs b/src/Uno/Prism.Uno/Common/BindingOperations.cs new file mode 100644 index 0000000000..49370d1b04 --- /dev/null +++ b/src/Uno/Prism.Uno/Common/BindingOperations.cs @@ -0,0 +1,7 @@ +namespace Prism; + +internal static class BindingOperations +{ + public static BindingExpression GetBinding(FrameworkElement instance, DependencyProperty property) => + instance.GetBindingExpression(property); +} diff --git a/src/Uno/Prism.Uno/Common/DesignerProperties.cs b/src/Uno/Prism.Uno/Common/DesignerProperties.cs new file mode 100644 index 0000000000..38c7c4f17e --- /dev/null +++ b/src/Uno/Prism.Uno/Common/DesignerProperties.cs @@ -0,0 +1,7 @@ +namespace Prism; + +internal static class DesignerProperties +{ + public static bool GetIsInDesignMode(DependencyObject _) => + Windows.ApplicationModel.DesignMode.DesignModeEnabled; +} diff --git a/src/Wpf/Prism.Wpf/Common/MvvmHelpers.cs b/src/Wpf/Prism.Wpf/Common/MvvmHelpers.cs index f6a6d2de21..e93bbc1554 100644 --- a/src/Wpf/Prism.Wpf/Common/MvvmHelpers.cs +++ b/src/Wpf/Prism.Wpf/Common/MvvmHelpers.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -13,7 +13,7 @@ public static class MvvmHelpers { #if HAS_WINUI /// - /// Sets the AutoWireViewModel property to true for the . + /// Sets the AutowireViewModel property to true for the . /// /// /// The AutoWireViewModel property will only be set to true if the view diff --git a/src/Wpf/Prism.Wpf/Extensions/DependencyObjectExtensions.cs b/src/Wpf/Prism.Wpf/Extensions/DependencyObjectExtensions.cs index 2d40fe8f87..ff2137fe56 100644 --- a/src/Wpf/Prism.Wpf/Extensions/DependencyObjectExtensions.cs +++ b/src/Wpf/Prism.Wpf/Extensions/DependencyObjectExtensions.cs @@ -12,11 +12,7 @@ internal static partial class DependencyObjectExtensions /// The to use to search for the property /// The property to search /// true if there is an active binding, otherwise false - public static bool HasBinding(this FrameworkElement instance, DependencyProperty property) -#if HAS_WINUI - => instance.GetBindingExpression(property) != null; -#else - => BindingOperations.GetBinding(instance, property) != null; -#endif + public static bool HasBinding(this FrameworkElement instance, DependencyProperty property) => + BindingOperations.GetBinding(instance, property) is not null; } } diff --git a/src/Wpf/Prism.Wpf/Mvvm/ViewModelLocator.cs b/src/Wpf/Prism.Wpf/Mvvm/ViewModelLocator.cs index b55568aa55..0ee605e37c 100644 --- a/src/Wpf/Prism.Wpf/Mvvm/ViewModelLocator.cs +++ b/src/Wpf/Prism.Wpf/Mvvm/ViewModelLocator.cs @@ -40,9 +40,7 @@ public static void SetAutoWireViewModel(DependencyObject obj, bool? value) private static void AutoWireViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { -#if !HAS_WINUI if (!DesignerProperties.GetIsInDesignMode(d)) -#endif { var value = (bool?)e.NewValue; if (value.HasValue && value.Value) diff --git a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionManager.cs b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionManager.cs index 327ef18fb6..4b2890cda1 100644 --- a/src/Wpf/Prism.Wpf/Navigation/Regions/RegionManager.cs +++ b/src/Wpf/Prism.Wpf/Navigation/Regions/RegionManager.cs @@ -232,11 +232,7 @@ public static void UpdateRegions() private static bool IsInDesignMode(DependencyObject element) { -#if HAS_WINUI - return Windows.ApplicationModel.DesignMode.DesignModeEnabled; -#else return DesignerProperties.GetIsInDesignMode(element); -#endif } #endregion From 190c61342bc9f64d6bc17eb4ac363029cca8f040 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Sat, 24 Feb 2024 21:07:17 -0600 Subject: [PATCH 8/8] chore: update Constants for Uno/WPF --- Directory.Build.props | 6 +- .../Prism.Forms/Modularity/ModuleCatalog.cs | 2 +- .../Prism.Forms/Modularity/ModuleInfo.cs | 2 +- .../MicrosoftDependencyInjectionExtensions.cs | 2 +- .../Prism.DryIoc.Uno.WinUI.csproj | 1 - .../DependencyObjectExtensions.Uno.cs | 59 ++++++++----------- src/Uno/Prism.Uno/Prism.Uno.WinUI.csproj | 1 - src/Wpf/Prism.Wpf/Common/MvvmHelpers.cs | 2 +- src/Wpf/Prism.Wpf/Dialogs/Dialog.cs | 2 +- .../Dialogs/IDialogServiceCompatExtensions.cs | 2 +- .../Dialogs/KnownDialogParameters.cs | 2 +- .../Interactivity/CommandBehaviorBase.cs | 2 +- src/Wpf/Prism.Wpf/Mvvm/ViewModelLocator.cs | 2 +- .../DelayedRegionCreationBehavior.cs | 4 +- .../RegionManagerRegistrationBehavior.cs | 2 +- .../Navigation/Regions/INavigationAware.cs | 3 +- .../PrismInitializationExtensions.cs | 4 +- 17 files changed, 46 insertions(+), 52 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index b6cf57ec0f..43748d9883 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -58,6 +58,9 @@ --> + + $(DefineConstants);WPF + @@ -67,7 +70,8 @@ - $(DefineConstants);UNO_WINUI_PROJECT + $(DefineConstants);UNO_WINUI + $(DefineConstants);UNO_WASM diff --git a/src/Forms/Prism.Forms/Modularity/ModuleCatalog.cs b/src/Forms/Prism.Forms/Modularity/ModuleCatalog.cs index 9fe37060dd..2822ae2d62 100644 --- a/src/Forms/Prism.Forms/Modularity/ModuleCatalog.cs +++ b/src/Forms/Prism.Forms/Modularity/ModuleCatalog.cs @@ -7,7 +7,7 @@ namespace Prism.Modularity /// application. Each module is described in a class, that records the /// name and type of the module. /// -#if HAS_WINUI +#if UNO_WINUI [Microsoft.UI.Xaml.Markup.ContentProperty(Name = nameof(Items))] #else [Xamarin.Forms.ContentProperty(nameof(Items))] diff --git a/src/Forms/Prism.Forms/Modularity/ModuleInfo.cs b/src/Forms/Prism.Forms/Modularity/ModuleInfo.cs index 3a59795c65..ec68f434aa 100644 --- a/src/Forms/Prism.Forms/Modularity/ModuleInfo.cs +++ b/src/Forms/Prism.Forms/Modularity/ModuleInfo.cs @@ -9,7 +9,7 @@ namespace Prism.Modularity /// /// Defines the metadata that describes a module. /// -#if HAS_WINUI +#if UNO_WINUI [Microsoft.UI.Xaml.Markup.ContentProperty(Name = nameof(DependsOn))] #else [Xamarin.Forms.ContentProperty(nameof(DependsOn))] diff --git a/src/Maui/Prism.Maui/Ioc/MicrosoftDependencyInjectionExtensions.cs b/src/Maui/Prism.Maui/Ioc/MicrosoftDependencyInjectionExtensions.cs index 6b95e9a87b..7ea797a9bb 100644 --- a/src/Maui/Prism.Maui/Ioc/MicrosoftDependencyInjectionExtensions.cs +++ b/src/Maui/Prism.Maui/Ioc/MicrosoftDependencyInjectionExtensions.cs @@ -8,7 +8,7 @@ namespace Prism.Ioc; /// public static class MicrosoftDependencyInjectionExtensions { -#if !UNO_WINUI_PROJECT +#if !UNO_WINUI private static readonly Type PageType = typeof(Page); public static IServiceCollection RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView>(this IServiceCollection services, string name = null) diff --git a/src/Uno/Prism.DryIoc.Uno/Prism.DryIoc.Uno.WinUI.csproj b/src/Uno/Prism.DryIoc.Uno/Prism.DryIoc.Uno.WinUI.csproj index c2103d4f2d..0500408e6a 100644 --- a/src/Uno/Prism.DryIoc.Uno/Prism.DryIoc.Uno.WinUI.csproj +++ b/src/Uno/Prism.DryIoc.Uno/Prism.DryIoc.Uno.WinUI.csproj @@ -5,7 +5,6 @@ $(NoWarn);1591 Prism.DryIoc.Uno Prism.DryIoc.Uno.WinUI - $(DefineConstants);HAS_WINUI enable