protected void ReplaceAll(IStylesheetNode node) { ClearChildren(); StylesheetText = node.StylesheetText; foreach (var child in node.Children) { AppendChild(child); } }
private static void Teardown(IStylesheetNode child) { if (!(child is Rule rule)) { return; } rule.Parent = null; rule.Owner = null; }
private void Setup(IStylesheetNode child) { if (!(child is Rule rule)) { return; } rule.Owner = this as Stylesheet; rule.Parent = this as IRule; }
public void RemoveChild(IStylesheetNode child) { Teardown(child); var isRemoved = _children.Remove(child); if (!isRemoved) { throw new InvalidOperationException($"Child node \"{child}\" was not removed from the stylesheet node \"{this}\""); } }
private static void Teardown(IStylesheetNode child) { var rule = child as Rule; if (rule == null) { return; } rule.Parent = null; rule.Owner = null; }
public void InsertBefore(IStylesheetNode referenceChild, IStylesheetNode child) { if (referenceChild != null) { var index = _children.IndexOf(referenceChild); InsertChild(index, child); } else { AppendChild(child); } }
public void ReplaceChild(IStylesheetNode oldChild, IStylesheetNode newChild) { for (var i = 0; i < _children.Count; i++) { if (ReferenceEquals(oldChild, _children[i])) { Teardown(oldChild); Setup(newChild); _children[i] = newChild; return; } } }
public static IEnumerable<T> GetAll<T>(this IStylesheetNode node) where T : IStyleFormattable { if (node == null) throw new ArgumentNullException(nameof(node)); if (node is T) { yield return (T)node; } foreach (var entity in node.Children.SelectMany(m => m.GetAll<T>())) { yield return entity; } }
protected void ReplaceSingle(IStylesheetNode oldNode, IStylesheetNode newNode) { if (oldNode != null) { if (newNode != null) { ReplaceChild(oldNode, newNode); } else { RemoveChild(oldNode); } } else if (newNode != null) { AppendChild(newNode); } }
public static ICollection <Property> GetAllProperties(IStylesheetNode styleRule) { var declarations = new List <Property>(); foreach (var node in styleRule.Children) { if (node is Property declaration) { declarations.Add(declaration); } else { declarations.AddRange(GetAllProperties(node)); } } return(declarations); }
public void RemoveChild(IStylesheetNode child) { Teardown(child); _children.Remove(child); }
public void InsertChild(int index, IStylesheetNode child) { Setup(child); _children.Insert(index, child); }
public void AppendChild(IStylesheetNode child) { Setup(child); _children.Add(child); }