Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new CSS rule and appends it to the current node.
        /// </summary>
        /// <typeparam name="TRule">The type of rule to create.</typeparam>
        /// <param name="creator">The host of the rule.</param>
        /// <returns>The created rule.</returns>
        public static TRule AddNewRule <TRule>(this ICssRuleCreator creator)
            where TRule : ICssRule
        {
            var ruleFullName = typeof(TRule).FullName;
            var ruleType     = CssRuleType.Unknown;

            if (RuleMapping.TryGetValue(ruleFullName, out ruleType))
            {
                var rule = creator.AddNewRule(ruleType);

                if (rule is TRule)
                {
                    return((TRule)rule);
                }
            }

            return(default(TRule));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new CSS style rule and appends it to the current node. The
        /// given selector and declarations are set in the beginning.
        /// </summary>
        /// <param name="creator">The host of the rule.</param>
        /// <param name="selector">The selector to use, if any.</param>
        /// <param name="declarations">The declarations to set, if any.</param>
        /// <returns>The created style rule.</returns>
        public static ICssStyleRule AddNewStyle(this ICssRuleCreator creator, String selector = null, IDictionary <String, String> declarations = null)
        {
            var rule = creator.AddNewRule <ICssStyleRule>();

            if (!String.IsNullOrEmpty(selector))
            {
                rule.SelectorText = selector;
            }

            if (declarations != null)
            {
                foreach (var declaration in declarations)
                {
                    rule.Style.SetProperty(declaration.Key, declaration.Value);
                }
            }

            return(rule);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new CSS style rule and appends it to the current node.
 /// The given selector and declarations from an anonymous object are set
 /// in the beginning.
 /// </summary>
 /// <param name="creator">The host of the rule.</param>
 /// <param name="selector">The selector to use.</param>
 /// <param name="declarations">The declarations to set.</param>
 /// <returns>The created style rule.</returns>
 public static ICssStyleRule AddNewStyle(this ICssRuleCreator creator, String selector, Object declarations)
 {
     return(creator.AddNewStyle(selector, declarations.ToDictionary()));
 }