• R/O
  • HTTP
  • SSH
  • HTTPS

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

なろうブックマーク分析用ツールのPrism+MAUIサンプル実装


File Info

Rev. 25963e22509f33d08a861a9dfadd9425437419d0
Größe 2,377 Bytes
Zeit 2023-09-30 20:52:00
Autor yoshy
Log Message

[MOD] CleanAuLait.MAUI パッケージのリネームに伴う対応 (CleanAuLait.Prism.MAUI )

Content

using Prism.Common;

namespace TestNarou2.OuterEdge
{
    internal static class RegionNavigationRegistrationExtensionsPatched
    {
        /// <summary>
        /// Registers a <see cref="View"/> for region navigation.
        /// </summary>
        /// <typeparam name="TView">The Type of <see cref="View"/> to register</typeparam>
        /// <param name="containerRegistry"><see cref="IContainerRegistry"/> used to register type for Navigation.</param>
        /// <param name="name">The unique name to register with the View</param>
        public static IContainerRegistry RegisterForRegionNavigationPatched<TView>(this IContainerRegistry containerRegistry, string name = null)
            where TView : View =>
            containerRegistry.RegisterForNavigationWithViewModelPatched(typeof(TView), null, name);

        /// <summary>
        /// Registers a <see cref="View"/> for region navigation.
        /// </summary>
        /// <typeparam name="TView">The Type of <see cref="View" />to register</typeparam>
        /// <typeparam name="TViewModel">The ViewModel to use as the BindingContext for the View</typeparam>
        /// <param name="name">The unique name to register with the View</param>
        /// <param name="containerRegistry"></param>
        public static IContainerRegistry RegisterForRegionNavigationPatched<TView, TViewModel>(this IContainerRegistry containerRegistry, string name = null)
            where TView : View
            where TViewModel : class =>
            containerRegistry.RegisterForNavigationWithViewModelPatched(typeof(TView), typeof(TViewModel), name);

        private static IContainerRegistry RegisterForNavigationWithViewModelPatched(this IContainerRegistry containerRegistry, Type viewType, Type viewModelType, string name)
        {
            if (string.IsNullOrWhiteSpace(name))
                name = viewType.Name;

            if (viewModelType is not null && !viewModelType.IsInterface)
                containerRegistry.Register(viewModelType);

            containerRegistry.Register(viewType)
                .RegisterInstance(new ViewRegistration
                {
                    Name = name,
                    Type = ViewType.Region,
                    View = viewType,
                    ViewModel = viewModelType
                });

            return containerRegistry;
        }

    }
}