/// <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);
        }
Exemplo n.º 2
0
        public void CopyTo(HtmlAttributeRuleCollection collection)
        {
            Precondition.Require(collection,
                                 () => Error.ArgumentNull("collection"));

            collection.Clear();
            collection.AddRange(this);
        }
        IFluentAttributeRule IRuleSelector.Attributes(params string[] names)
        {
            Precondition.Require(names, () => Error.ArgumentNull("names"));
            HtmlAttributeRuleCollection collection = new HtmlAttributeRuleCollection();

            foreach (string name in names)
            {
                collection.Add(new HtmlAttributeRule(Document, name, HtmlAttributeOptions.Allowed));
            }

            return(collection);
        }
Exemplo n.º 4
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;
        }