Ejemplo n.º 1
0
        /// <summary>
        /// Gets merged RuleseteNode from the two RulesetNode
        /// </summary>
        /// <param name="otherRulesetNode"> another ruleset node</param>
        /// <returns> A new merged Ruleset Node.</returns>
        public RulesetNode GetMergedRulesetNode(RulesetNode otherRulesetNode)
        {
            List <SelectorNode> mySelectors             = new List <SelectorNode>(this.SelectorsGroupNode.SelectorNodes);
            List <SelectorNode> otherSelectors          = new List <SelectorNode>(otherRulesetNode.SelectorsGroupNode.SelectorNodes);
            ReadOnlyCollection <SelectorNode> unionList = mySelectors.Union(otherSelectors).ToList().AsReadOnly();

            List <DeclarationNode> myDeclarations        = new List <DeclarationNode>(this.Declarations);
            List <DeclarationNode> otherDeclarations     = new List <DeclarationNode>(otherRulesetNode.Declarations);
            List <DeclarationNode> mergedNewDeclarations = new List <DeclarationNode>();

            foreach (var myDeclaration in this.Declarations)
            {
                bool unique = true;
                foreach (var otherDeclaration in otherRulesetNode.Declarations)
                {
                    if (myDeclaration.Equals(otherDeclaration))
                    {
                        unique = false;
                        otherDeclarations.Remove(otherDeclaration);
                        break;
                    }
                }

                if (!unique)
                {
                    myDeclarations.Remove(myDeclaration);
                    mergedNewDeclarations.Add(myDeclaration);
                }
            }

            this.Declarations             = myDeclarations.AsReadOnly();
            otherRulesetNode.Declarations = otherDeclarations.AsReadOnly();
            return(new RulesetNode(new SelectorsGroupNode(unionList), mergedNewDeclarations.AsReadOnly(), this.ImportantComments));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rulesetNode"></param>
        /// <returns></returns>
        public bool ShouldMergeWith(RulesetNode rulesetNode)
        {
            int intersection = 0;

            foreach (var myDeclaration in this.Declarations)
            {
                foreach (var otherDeclaration in rulesetNode.Declarations)
                {
                    if (myDeclaration.Equals(otherDeclaration))
                    {
                        intersection++;
                        break;
                    }
                }

                if (intersection > 1)
                {
                    break;
                }
            }

            return(intersection > 1 || (intersection == 1 && (Declarations.Count == 1 || rulesetNode.Declarations.Count == 1)));
            //return intersection > 1;
        }