CssRuleSet

Namespace: OpenXmlPowerTools
We found 10 examples in language CSharp for this search. You will see 21 fragments of code.
        public void AddRuleSet(CssRuleSet ruleSet)
        {
            _ruleSets.Add(ruleSet);
        }
        public IEnumerable<CssRuleSet> GetRuleSetIter()
        {
            foreach (CssRuleSet ruleSet in _ruleSets)
            {
                yield return ruleSet;
            }
        }

        [NotNull]
        T Inline<T>(ICollection<CssRuleSet> cssRules, T element) where T : IHtmlElement;

        private static IEnumerable<CssRuleSet> FindCssRules(IEnumerable<CssRuleSet> cssRules, IEnumerable<SoftString> selectors)
        {
            return
                from cssRule in cssRules
                where selectors.Contains(cssRule.Selector)
                select cssRule;
        }

        private static string ConcatenateCssRules(IEnumerable<CssRuleSet> cssRules)
        {
            return string.Join(" ", cssRules.Select(cssRule => $"{cssRule.Declarations.Trim().TrimEnd(';')};"));
        }

// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.

namespace Gtk {

	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Runtime.InteropServices;

#region Autogenerated code
	public partial class CssRuleset : GLib.Opaque {

		public CssRuleset(IntPtr raw) : base(raw) {}

#endregion
	}
}

// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.

namespace Gtk {

	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Runtime.InteropServices;

#region Autogenerated code
	public partial class CssRuleset : GLib.Opaque {

		public CssRuleset(IntPtr raw) : base(raw) {}


		// Internal representation of the wrapped structure ABI.
		static GLib.AbiStruct _abi_info = null;
		static public GLib.AbiStruct abi_info {
			get {
				if (_abi_info == null)
					_abi_info = new GLib.AbiStruct (new List<GLib.AbiField>{ 
					});

				return _abi_info;
			}
		}


		// End of the ABI representation.

#endregion
	}
}

        public CssRuleSet ParseCssPropertyDeclarationList(char[] textBuffer)
        {
            this.textBuffer = textBuffer;
            Reset();
            //------------- 
            _currentRuleSet = new CssRuleSet();
            //-------------
            this.parseState = CssParseState.BlockBody;
            lexer.Lex(textBuffer);
            EvaluateRuleSet(_currentRuleSet);
            return _currentRuleSet;
        }

using System.Collections.Generic;
using JetBrains.Annotations;

namespace Reusable.MarkupBuilder.Html
{
    [PublicAPI]
    public class Css : List<CssRuleSet>
    {
        public Css()
        {
        }

        public Css(IEnumerable<CssRuleSet> cssRuleSets) : base(cssRuleSets)
        {
        }
    }
}

// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.

namespace Gtk {

	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Runtime.InteropServices;

#region Autogenerated code
	public partial class CssRuleset : GLib.Opaque {

		public CssRuleset(IntPtr raw) : base(raw) {}


		// Internal representation of the wrapped structure ABI.
		static GLib.AbiStruct _abi_info = null;
		static public GLib.AbiStruct abi_info {
			get {
				if (_abi_info == null)
					_abi_info = new GLib.AbiStruct (new List<GLib.AbiField>{ 
					});

				return _abi_info;
			}
		}


		// End of the ABI representation.

#endregion
	}
}

        [NotNull]
        Css Parse([NotNull] string css);
        
        public Css Parse(string css)
        {
            if (css == null) throw new ArgumentNullException(nameof(css));

            var cssRules = MatchRules(css);
            return new Css(cssRules);
        }

        [NotNull]
        [ItemNotNull]
        private static IEnumerable<CssRuleSet> MatchRules(string css)
        {
            css = RemoveLineBreaks(css);
            
            // https://regex101.com/r/iJ8MZX/3
            return
                from selectorMatches in Regex
                    .Matches(css, @"(?<selectors>[a-z0-9_\-\.,\s#]+)\s*{(?<declarations>.+?)}", RegexOptions.IgnoreCase)
                    .Cast<Match>()
                from selector in SplitSelectors(selectorMatches.Groups["selectors"].Value)
                select new CssRuleSet
                {
                    Selector = selector,
                    Declarations = selectorMatches.Groups["declarations"].Value.Trim()
                };
        
            string RemoveLineBreaks(string value) => Regex.Replace(value, @"(\r\n|\r|\n)", string.Empty);
        }

        [NotNull]
        [ItemNotNull]
        private static IEnumerable<string> SplitSelectors(string selectors)
        {
            return
                Regex
                    .Split(selectors, @",")
                    .Where(Conditional.IsNotNullOrEmpty)
                    .Select(selector => selector.Trim().ToLowerInvariant());
        }

#if DEBUG
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(_elementSelector.ToString());
            sb.Append('{');
            int j = _decls.Count;
            for (int i = 0; i < j; ++i)
            {
                sb.Append(_decls[i].ToString());
                if (i < j - 1)
                {
                    sb.Append(';');
                }
            }

            sb.Append('}');
            return sb.ToString();
        }
#endif
        public void PrepareExpression(CssCombinatorOperator combinator)
        {
            switch (combinator)
            {
                default:
                    {
                    }
                    break;
                case CssCombinatorOperator.AdjacentSibling:
                    {
                        throw new NotSupportedException();
                    }
                    break;
                case CssCombinatorOperator.Child:
                    {
                        throw new NotSupportedException();
                    }
                    break;
                case CssCombinatorOperator.Descendant:
                    {
                        throw new NotSupportedException();
                    }
                    break;
                case CssCombinatorOperator.GeneralSibling:
                    {
                        throw new NotSupportedException();
                    }
                    break;
                case CssCombinatorOperator.List:
                    {
                        CssCompundElementSelector combinatorExpr = new CssCompundElementSelector(combinator);
                        combinatorExpr.LeftSelector = _elementSelector;
                        _elementSelector = combinatorExpr;
                    }
                    break;
            }
        }
        public void AddSelector(CssSimpleElementSelector primExpr)
        {
#if DEBUG
            if (primExpr == null)
            {
            }
#endif
            if (_elementSelector == null)
            {
                _elementSelector = primExpr;
            }
            else
            {
                CssCompundElementSelector combinatorExpr = _elementSelector as CssCompundElementSelector;
                if (combinatorExpr != null)
                {
                    combinatorExpr.RightSelector = primExpr;
                }
                else
                {
                    CssSimpleElementSelector currentPrimExpr = _elementSelector as CssSimpleElementSelector;
                    if (currentPrimExpr != null)
                    {
                        combinatorExpr = new CssCompundElementSelector(CssCombinatorOperator.Descendant);
                        combinatorExpr.LeftSelector = _elementSelector;
                        combinatorExpr.RightSelector = primExpr;
                        _elementSelector = combinatorExpr;
                    }
                    else
                    {
                    }
                }
            }
        }
        public void AddCssCodeProperty(CssPropertyDeclaration property)
        {
            _decls.Add(property);
        }
        public void RemoveCssProperty(WellknownCssPropertyName wellknownName)
        {
            if (wellknownName == WellknownCssPropertyName.Unknown)
            {
                //can't delete
                return;
            }
            for (int i = _decls.Count - 1; i >= 0; --i)
            {
                if (_decls[i].WellknownPropertyName == wellknownName)
                {
                    _decls.RemoveAt(i);
                }
            }
        }
        //
        public CssElementSelector GetSelector() => _elementSelector;
        //
        public IEnumerable<CssPropertyDeclaration> GetAssignmentIter()
        {
            foreach (var assignment in _decls)
            {
                yield return assignment;
            }
        }


        /* (non-Javadoc)
        * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
        */
        public virtual int Compare(CssRuleSet o1, CssRuleSet o2) {
            return selectorComparator.Compare(o1.GetSelector(), o2.GetSelector());
        }

OpenXmlPowerTools.HtmlToWml.CSS.CssRuleSet : ItfDeclarationContainer

Constructors :

public CssRuleSet()

Methods :

public List<CssSelector> get_Selectors()
public Void set_Selectors(List<CssSelector> value = )
public List<CssDeclaration> get_Declarations()
public Void set_Declarations(List<CssDeclaration> value = )
public String ToString()
public String ToString(Int32 indentLevel = )
public Type GetType()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()