Exemplo n.º 1
0
        public static IRule AddCssStringSelector(this ICollection <IRule> rules, string selectorName)
        {
            if (string.IsNullOrWhiteSpace(selectorName))
            {
                throw new ArgumentNullException(nameof(selectorName));
            }

            Rule?rule = new()
            {
                Selector = new CssStringSelector {
                    SelectorName = selectorName
                },
                Properties = new CssString(),
            };

            rules.Add(rule);
            return(rule);
        }
Exemplo n.º 2
0
        public static CssString AppendCssStyles(this CssString cssString, params string[] cssStyles)
        {
            if (!cssStyles.Any())
            {
                return(cssString);
            }

            int totalCharLength = cssStyles.Select(x => x.Length).Sum() + cssStyles.Length;

            // Use string.Create and Spans to highly optimize the string concatenation (no allocations)
            string?combinedString = string.Create(totalCharLength, cssStyles, (chars, state) =>
            {
                int position = 0;
                foreach (string?cssString in state)
                {
                    cssString.AsSpan().CopyTo(chars[position..]);
                    position         += cssString.Length;
                    chars[position++] = ';'; // Append a semi-colon after each fragment
                }
Exemplo n.º 3
0
        public static CssString SetCssStyles(this CssString cssString, params string[] cssStyles)
        {
            if (!cssStyles.Any())
            {
                return(cssString);
            }

            var totalCharLength = cssStyles.Select(x => x.Length).Sum() + cssStyles.Count();

            // Use string.Create and Spans to highly optimize the string concatenation (no allocations)
            var combinedString = string.Create(totalCharLength, cssStyles, (chars, state) =>
            {
                var position = 0;
                foreach (var cssString in state)
                {
                    cssString.AsSpan().CopyTo(chars.Slice(position));
                    position         += cssString.Length;
                    chars[position++] = ';'; // Append a semi-colon after each fragment
                }
            });

            cssString.Css = combinedString;
            return(cssString);
        }