/// <summary> /// Get a builder for the element specified by id. /// </summary> public ElementBuilder Get(string id) { ElementBuilder builder; if (!SingleChildren.TryGetValue(id, out builder)) { _singleChildren.Add(id, builder = new ElementBuilder()); } return(builder); }
/// <summary> /// Remove the specified child by id. /// </summary> public void RemoveChild(string id) { ElementBuilder builder; if (SingleChildren.TryGetValue(id, out builder)) { builder.Action = BuilderAction.Remove; } else { builder = new ElementBuilder(); builder.Action = BuilderAction.Remove; _singleChildren.Add(id, builder); } }
/// <summary> /// Add a child to the element builder to replace an existing id. /// </summary> public ElementBuilder ReplaceChild(string id, Element element, IAction <Element> onElement = null) { ElementBuilder builder; if (!SingleChildren.TryGetValue(id, out builder)) { _singleChildren.Add(id, builder = new ElementBuilder()); } builder.Action = BuilderAction.Replace; builder.Element = element; if (onElement != null) { builder._onBuilt = onElement; } return(builder); }
/// <summary> /// Add an attribute to be applied to the element of the specified id. /// </summary> public ElementBuilder AddContent(string id, Func <string> content, IAction <Element> onElement = null) { ElementBuilder builder; if (!SingleChildren.TryGetValue(id, out builder)) { _singleChildren.Add(id, builder = new ElementBuilder()); } if (builder.Content == null) { builder.Content = new ArrayRig <Teple <string, IFunc <string> > >(); } builder.Content.Add(new Teple <string, IFunc <string> >(null, new FuncSet <string>(content))); if (onElement != null) { builder._onBuilt = onElement; } return(builder); }
/// <summary> /// Add a child to the current element builder. /// </summary> public ElementBuilder AddChild(string id, Element element, IAction <Element> onElement = null) { ArrayRig <ElementBuilder> builders; if (!MultiChildren.TryGetValue(id, out builders)) { _multiChildren.Add(id, builders = new ArrayRig <ElementBuilder>()); } var builder = new ElementBuilder(); builders.Add(builder); builder.Action = BuilderAction.Add; builder.Element = element; if (onElement != null) { builder._onBuilt = onElement; } return(builder); }
/// <summary> /// Add a child to the current element builder. The specified callback function will /// be called if an element cannot be found for the specified key. /// </summary> public ElementBuilder AddChild(string id, string key, IFunc <Element> getFallback, IAction <Element> onElement = null) { ArrayRig <ElementBuilder> builders; if (!MultiChildren.TryGetValue(id, out builders)) { _multiChildren.Add(id, builders = new ArrayRig <ElementBuilder>()); } var builder = new ElementBuilder(); builders.Add(builder); builder.Action = BuilderAction.Add; builder.GetElement = getFallback; builder.Key = key; if (onElement != null) { builder._onBuilt = onElement; } return(builder); }