コード例 #1
0
ファイル: HotReloadHelper.cs プロジェクト: jrockhub/maui
 public static void UnRegister(IHotReloadableView view)
 {
     if (!IsEnabled)
     {
         return;
     }
     currentViews.Remove(view);
 }
コード例 #2
0
ファイル: HotReloadHelper.cs プロジェクト: jrockhub/maui
 public static void Register(IHotReloadableView view, params object[] parameters)
 {
     if (!IsEnabled)
     {
         return;
     }
     currentViews[view] = parameters;
 }
コード例 #3
0
ファイル: HotReloadHelper.cs プロジェクト: jrockhub/maui
        public static bool IsReplacedView(IHotReloadableView view, IView newView)
        {
            if (!IsEnabled)
            {
                return(false);
            }
            if (view == null || newView == null)
            {
                return(false);
            }

            if (!replacedViews.TryGetValue(view.GetType().FullName !, out var newViewType))
            {
                return(false);
            }
            return(newView.GetType() == newViewType);
        }
コード例 #4
0
ファイル: HotReloadHelper.cs プロジェクト: jrockhub/maui
        public static IView GetReplacedView(IHotReloadableView view)
        {
            if (!IsEnabled)
            {
                return(view);
            }

            var viewType = view.GetType();

            if (!replacedViews.TryGetValue(viewType.FullName !, out var newViewType) || viewType == newViewType)
            {
                return(view);
            }

            currentViews.TryGetValue(view, out var parameters);
            try
            {
                //TODO: Add in a way to use IoC and DI
                var newView = (IView)(parameters?.Length > 0 ? Activator.CreateInstance(newViewType, args: parameters) : Activator.CreateInstance(newViewType)) !;
                TransferState(view, newView);
                return(newView);
            }
            catch (MissingMethodException)
            {
                Debug.WriteLine("You are using trying to HotReload a view that requires Parameters. Please call `HotReloadHelper.Register(this, params);` in the constructor;");
                //TODO: Notifiy that we couldnt hot reload.
                return(view);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Error Hotreloading type: {newViewType}");
                Debug.WriteLine(ex);
                //TODO: Notifiy that we couldnt hot reload.
                return(view);
            }
        }
コード例 #5
0
ファイル: HotReloadHelper.cs プロジェクト: jrockhub/maui
 public static void AddActiveView(IHotReloadableView view) => ActiveViews.Add(view);
コード例 #6
0
ファイル: HotReloadHelper.cs プロジェクト: jrockhub/maui
 static void TransferState(IHotReloadableView oldView, IView newView)
 {
     oldView.TransferState(newView);
 }