Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
            }
        }