public static void UnRegister(IHotReloadableView view) { if (!IsEnabled) { return; } currentViews.Remove(view); }
public static void Register(IHotReloadableView view, params object[] parameters) { if (!IsEnabled) { return; } currentViews[view] = parameters; }
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); }
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); } }
public static void AddActiveView(IHotReloadableView view) => ActiveViews.Add(view);
static void TransferState(IHotReloadableView oldView, IView newView) { oldView.TransferState(newView); }