/// <summary>
        /// Adds a top-level rule for the element.
        /// </summary>
        /// <param name="builder">The selector function.</param>
        public IRuleAppender Treat(Func <IRuleSelector, IRuleBuilder> builder)
        {
            Precondition.Require(builder, () => Error.ArgumentNull("inner"));
            IRuleBuilder rule = builder(this);

            HtmlElementRule             elem = (rule as HtmlElementRule);
            HtmlAttributeRule           attr = (rule as HtmlAttributeRule);
            HtmlElementRuleCollection   ec   = (rule as HtmlElementRuleCollection);
            HtmlAttributeRuleCollection ac   = (rule as HtmlAttributeRuleCollection);

            if (elem != null)
            {
                AddElementRule(elem);
            }
            else if (ec != null)
            {
                AddElementRules(ec);
            }
            else if (attr != null)
            {
                AddAttributeRule(attr);
            }
            else if (ac != null)
            {
                AddAttributeRules(ac);
            }
            else
            {
                throw Error.UnsupportedElementRule("builder");
            }

            return(this);
        }
        public void CopyTo(HtmlElementRuleCollection collection)
        {
            Precondition.Require(collection,
                                 () => Error.ArgumentNull("collection"));

            collection.Clear();
            collection.AddRange(this);
        }
Пример #3
0
        public HtmlElementRule(HtmlElementRule parent,
                               string name, HtmlElementOptions flags)
        {
            Precondition.Defined(name,
                                 () => Error.ArgumentNull("name"));

            _name       = name;
            _options    = flags;
            _children   = new HtmlElementRuleCollection();
            _attributes = new HtmlAttributeRuleCollection();
            _parent     = parent;
        }
        IFluentElementRule IRuleSelector.Elements(params string[] names)
        {
            Precondition.Require(names, () => Error.ArgumentNull("names"));
            HtmlElementRuleCollection collection = new HtmlElementRuleCollection();

            foreach (string name in names)
            {
                collection.Add(new HtmlElementRule(Document, name, HtmlElementOptions.Allowed |
                                                   HtmlElementOptions.AllowContent | HtmlElementOptions.SelfClosing));
            }

            return(collection);
        }