/// <summary> /// Call this method from the controller to perform routing. /// </summary> /// <param name="viewData">Routing view data.</param> /// <param name="oModel">Model to be passed to the view.</param> /// <returns>View URL.</returns> public static string Route(ref RoutingViewData viewData, out object oModel) { RouteTemplate template = viewData?.ActiveTemplate; if (template != null) { try { oModel = template.VMType != null?VMController.CreateInstance(template.VMType, null) : null; if (oModel is IRoutable) { (oModel as IRoutable).RouteUrl(ref viewData); } else { viewData = null; } return(template.ViewUrl); } catch (Exception ex) { Trace.Fail(ex.ToString()); } } oModel = null; return(null); }
/// <summary> /// Call this method from the controller to perform routing. /// </summary> /// <param name="viewData">Routing view data.</param> /// <param name="oModel">Model to be passed to the view.</param> /// <returns>View URL.</returns> public static string Route(ref RoutingViewData viewData, out IRoutable oModel) { var template = viewData.ActiveTemplate; if (template != null) { try { oModel = template.VMType != null?VMController.CreateInstance(template.VMType, null) as IRoutable : null; if (oModel != null) { oModel.RouteUrl(ref viewData); } return(template.ViewUrl); } catch (Exception ex) { Trace.Fail(ex.ToString()); } } oModel = null; return(null); }
/// <summary> /// Resolves view model of a route template. /// </summary> /// <param name="template">Route template.</param> /// <returns>View model object.</returns> private static object ResolveVM(RouteTemplate template) { Type vmType = template.VMType; if (vmType == null) { vmType = VMController.VMTypes.Find(x => x.Name == template.Id)?.Type; } return(vmType != null && vmType != typeof(void) ? VMController.CreateInstance(vmType, null) : null); }
/// <summary> /// Creates the view model for a widget. /// </summary> public BaseVM CreateWidgetVM(string iWidgetTypeName, string iWidgetId) { var widgetType = GetType().GetTypeInfo().Assembly.GetExportedTypes().FirstOrDefault(i => i.Name == iWidgetTypeName); return(VMController.CreateInstance(widgetType, new object[] { iWidgetId }) as BaseVM); }