/// <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);
        }
예제 #2
0
 public HtmlAttributeContext(HtmlAttributeRule rule,
                             IValueSet parameters)
     : base(parameters)
 {
     Precondition.Require(rule, () => Error.ArgumentNull("rule"));
     _rule = rule;
 }
예제 #3
0
        protected HtmlAttributeResult ConvertAttribute(HtmlElementRule element, XmlAttribute attribute)
        {
            HtmlAttributeRule    attrRule = GetAttributeRule(element, attribute.LocalName);
            HtmlAttributeContext context  = new HtmlAttributeContext(attrRule.Clone(), Parameters);

            if (attrRule.HasConverter)
            {
                attribute = attrRule.Converter(context, attribute);
                if (attribute == null)
                {
                    return(null);
                }

                if (!MatchName(attribute, attrRule))
                {
                    attrRule = GetAttributeRule(element, attribute.LocalName);
                }

                if ((attrRule.Options & HtmlAttributeOptions.Generated) == HtmlAttributeOptions.Generated)
                {
                    attrRule          = attrRule.Clone();
                    attrRule.Options |= HtmlAttributeOptions.Allowed;
                }
            }
            return(new HtmlAttributeResult(attribute, attrRule));
        }
		public HtmlAttributeContext(HtmlAttributeRule rule,
			IValueSet parameters)
			: base(parameters)
		{
			Precondition.Require(rule, () => Error.ArgumentNull("rule"));
			_rule = rule;
		}
예제 #5
0
        internal HtmlAttributeRule Clone(HtmlElementRule parent)
        {
            HtmlAttributeRule current = Clone();

            current._element = parent;

            return(current);
        }
예제 #6
0
        public virtual HtmlAttributeRule AddAttributeRule(HtmlAttributeRule rule)
        {
            Precondition.Require(rule, () => Error.ArgumentNull("rule"));
            HtmlAttributeRule current = (rule.Element == this) ? rule : rule.Clone(this);

            _attributes[current.Name] = current;

            return(current);
        }
예제 #7
0
        public HtmlAttributeRule Clone()
        {
            HtmlAttributeRule current = new HtmlAttributeRule(_element, _name, _options);

            current._converter    = _converter;
            current._defaultValue = _defaultValue;
            current._pattern      = _pattern;

            return(current);
        }
        public HtmlAttributeResult(XmlAttribute attribute,
                                   HtmlAttributeRule rule)
        {
            Precondition.Require(attribute, () =>
                                 Error.ArgumentNull("attribute"));
            Precondition.Require(rule, () =>
                                 Error.ArgumentNull("rule"));

            _attribute = attribute;
            _rule      = rule;
        }
		public HtmlAttributeResult(XmlAttribute attribute, 
			HtmlAttributeRule rule)
		{
			Precondition.Require(attribute, () =>
				Error.ArgumentNull("attribute"));
			Precondition.Require(rule, () =>
				Error.ArgumentNull("rule"));

			_attribute = attribute;
			_rule = rule;
		}
예제 #10
0
        public override bool Equals(object obj)
        {
            if (Object.ReferenceEquals(this, obj))
            {
                return(true);
            }

            HtmlAttributeRule rule = (obj as HtmlAttributeRule);

            if (Object.ReferenceEquals(rule, null))
            {
                return(false);
            }

            if (rule.Name.Equals(_name, StringComparison.OrdinalIgnoreCase))
            {
                return(_element.Equals(rule._element));
            }

            return(false);
        }
 /// <summary>
 /// Adds a top-level rule for the attribute. In most cases, the rule is ignored.
 /// </summary>
 /// <param name="rule">A new sub-rule to add.</param>
 protected virtual HtmlAttributeRule AddAttributeRule(HtmlAttributeRule rule)
 {
     Precondition.Require(rule, () => Error.ArgumentNull("rule"));
     return Document.AddAttributeRule(rule);
 }
예제 #12
0
 public HtmlAttributeContext(HtmlAttributeRule rule)
     : this(rule, null)
 {
 }
예제 #13
0
 protected bool MatchName(XmlAttribute attribute, HtmlAttributeRule rule)
 {
     return(String.Equals(attribute.LocalName, rule.Name, StringComparison.OrdinalIgnoreCase));
 }
        public HtmlAttributeRule Clone()
        {
            HtmlAttributeRule current = new HtmlAttributeRule(_element, _name, _options);
            current._converter = _converter;
            current._defaultValue = _defaultValue;
            current._pattern = _pattern;

            return current;
        }
예제 #15
0
		protected bool MatchName(XmlAttribute attribute, HtmlAttributeRule rule)
		{
			return String.Equals(attribute.LocalName, rule.Name, StringComparison.OrdinalIgnoreCase);
		}
예제 #16
0
 /// <summary>
 /// Adds a top-level rule for the attribute. In most cases, the rule is ignored.
 /// </summary>
 /// <param name="rule">A new sub-rule to add.</param>
 protected virtual HtmlAttributeRule AddAttributeRule(HtmlAttributeRule rule)
 {
     Precondition.Require(rule, () => Error.ArgumentNull("rule"));
     return(Document.AddAttributeRule(rule));
 }
예제 #17
0
		public virtual HtmlAttributeRule AddAttributeRule(HtmlAttributeRule rule)
		{
			Precondition.Require(rule, () => Error.ArgumentNull("rule"));
			HtmlAttributeRule current = (rule.Element == this) ? rule : rule.Clone(this);
			_attributes[current.Name] = current;

			return current;
		}
		public HtmlAttributeContext(HtmlAttributeRule rule)
			: this(rule, null)
		{
		}