Class CssComponentValue
A CSS Syntax 3 component value: a preserved token, a function or a simple block. Declarations, preludes and values are lists of these. ToString() serializes back to CSS text.
public abstract record CssComponentValue : IEquatable<CssComponentValue>
- Inheritance
-
CssComponentValue
- Implements
- Derived
- Inherited Members
Examples
// CSS Syntax 3 tokens, and component values: tokens, functions and simple blocks.
IReadOnlyList<CssToken> tokens = CssTokenizer.Tokenize("rgb(255 0 0 / 50%) 12px");
CssToken first = tokens[0];
bool isFunction = first.Kind == CssTokenKind.Function; // "rgb(" at line 1, column 1
IReadOnlyList<CssComponentValue> values = CssComponentValue.ParseList("calc(100% - 2px) [a] x");
var calc = (CssFunction)values[0];
var block = (CssSimpleBlock)values[2];
var word = (CssTokenValue)values[4];
string text = CssComponentValue.Serialize(values); // "calc(100% - 2px) [a] x"
Remarks
Component values compare by content: two functions are equal when their names and arguments are; source positions are not compared.
Properties
Column
Gets the 1-based column the value starts at, or 0 when unknown.
public abstract int Column { get; }
Property Value
Line
Gets the 1-based line the value starts on, or 0 when unknown.
public abstract int Line { get; }
Property Value
Methods
ParseList(string, CssParseOptions?)
Parses CSS text as a list of component values (CSS Syntax 3, "parse a list of component values").
public static IReadOnlyList<CssComponentValue> ParseList(string css, CssParseOptions? options = null)
Parameters
cssstringThe CSS text.
optionsCssParseOptionsOptions for error reporting.
Returns
- IReadOnlyList<CssComponentValue>
The component values, including whitespace.
Examples
// CSS Syntax 3 tokens, and component values: tokens, functions and simple blocks.
IReadOnlyList<CssToken> tokens = CssTokenizer.Tokenize("rgb(255 0 0 / 50%) 12px");
CssToken first = tokens[0];
bool isFunction = first.Kind == CssTokenKind.Function; // "rgb(" at line 1, column 1
IReadOnlyList<CssComponentValue> values = CssComponentValue.ParseList("calc(100% - 2px) [a] x");
var calc = (CssFunction)values[0];
var block = (CssSimpleBlock)values[2];
var word = (CssTokenValue)values[4];
string text = CssComponentValue.Serialize(values); // "calc(100% - 2px) [a] x"
Serialize(IEnumerable<CssComponentValue>)
Serializes a list of component values as CSS text.
public static string Serialize(IEnumerable<CssComponentValue> values)
Parameters
valuesIEnumerable<CssComponentValue>The values.
Returns
- string
The CSS text.
ToString()
Serializes the value as CSS text.
public override sealed string ToString()
Returns
- string
The CSS text.