예제 #1
0
 protected void ReplaceAll(IStylesheetNode node)
 {
     ClearChildren();
     StylesheetText = node.StylesheetText;
     foreach (var child in node.Children)
     {
         AppendChild(child);
     }
 }
예제 #2
0
 private static void Teardown(IStylesheetNode child)
 {
     if (!(child is Rule rule))
     {
         return;
     }
     rule.Parent = null;
     rule.Owner  = null;
 }
예제 #3
0
 private void Setup(IStylesheetNode child)
 {
     if (!(child is Rule rule))
     {
         return;
     }
     rule.Owner  = this as Stylesheet;
     rule.Parent = this as IRule;
 }
예제 #4
0
        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}\"");
            }
        }
예제 #5
0
        private static void Teardown(IStylesheetNode child)
        {
            var rule = child as Rule;

            if (rule == null)
            {
                return;
            }
            rule.Parent = null;
            rule.Owner  = null;
        }
예제 #6
0
 public void InsertBefore(IStylesheetNode referenceChild, IStylesheetNode child)
 {
     if (referenceChild != null)
     {
         var index = _children.IndexOf(referenceChild);
         InsertChild(index, child);
     }
     else
     {
         AppendChild(child);
     }
 }
예제 #7
0
 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;
         }
     }
 }
예제 #8
0
        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;
            }
        }
예제 #9
0
 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);
        }
예제 #11
0
 public void RemoveChild(IStylesheetNode child)
 {
     Teardown(child);
     _children.Remove(child);
 }
예제 #12
0
 public void InsertChild(int index, IStylesheetNode child)
 {
     Setup(child);
     _children.Insert(index, child);
 }
예제 #13
0
 public void AppendChild(IStylesheetNode child)
 {
     Setup(child);
     _children.Add(child);
 }