/// <summary>Method repeats supplied HTML template for each item in the list</summary> /// <typeparam name="TViewModelItem">Type of view model item</typeparam> /// <param name="viewModelItems">The list of view model items</param> /// <param name="template">HTMLlayout to be repeated for each view model item</param> /// <returns>Container tag</returns> public virtual ContainerTag ForEach <TViewModelItem>(IEnumerable <TViewModelItem> viewModelItems, Func <TViewModelItem, ContainerTag, ContainerTag> template) { var parentContainer = new OperatorTag <IEnumerable <TViewModelItem> >(viewModelItems); foreach (var viewModelItem in viewModelItems) { var itemContainer = new OperatorTag <TViewModelItem>(viewModelItem); template(viewModelItem, itemContainer); parentContainer.Children.Add(itemContainer); } return(parentContainer); }
/// <summary>Method return container tag with assigned visibility dependant on the condition</summary> /// <param name="condition">Boolean condition on which to decide whether to show nested tags or not</param> /// <param name="Then">On TRUE condition, lambda returning the same container supplied as input parameter</param> /// <param name="Else">On ELSE condition, lambda returning the same container supplied as input parameter</param> /// <returns>Container tag</returns> public virtual ContainerTag If(bool condition, Func <ContainerTag, ContainerTag> Then, Func <ContainerTag, ContainerTag> Else) { var container = new OperatorTag <TViewModel>(default(TViewModel)); if (condition && Then != null) { Then(container); } if (!condition && Else != null) { Else(container); } return(container); }
/// <summary>Method return container tag with assigned visibility dependant on the condition</summary> /// <param name="condition">Boolean condition on which to decide whether to show nested tags or not</param> /// <param name="Then">On TRUE condition, lambda returning tag</param> /// <param name="Else">On ELSE condition, lambda returning tag</param> /// <returns>Container tag</returns> public virtual ContainerTag If(bool condition, Func <TreeLeafTag> Then, Func <TreeLeafTag> Else) { var container = new OperatorTag <TViewModel>(default(TViewModel)); if (condition && Then != null) { var item = Then(); container.Children.Add(item); } if (!condition && Else != null) { var item = Else(); container.Children.Add(item); } return(container); }