Table of Contents

Class CssNamespaces

Namespace
Egami.Css
Assembly
Egami.Css.dll

The namespace prefixes selectors may use (svg|rect, [xlink|href]) and the default namespace for type selectors, as @namespace rules declare them. Prefixes are case-sensitive.

public sealed class CssNamespaces
Inheritance
CssNamespaces
Inherited Members

Examples

// Selectors 4, matched right to left over ICssElement.
CssSelectorList list = CssSelectorList.Parse("g.layer > rect:first-child, :is(circle, ellipse)");
bool matches = list.Matches(rect);

CssSelector selector = list.Selectors[0];
CssSpecificity specificity = selector.Specificity; // (0, 2, 2)

// Namespace prefixes, as @namespace declares them.
var namespaces = new CssNamespaces();
namespaces.Set("svg", "http://www.w3.org/2000/svg");
bool inSvg = CssSelectorList.Parse("svg|rect", namespaces).Matches(rect);

// A pseudo-element never matches the element itself; the cascade asks for it by name.
CssSelector before = CssSelectorList.Parse("rect::before").Selectors[0];
bool beforeMatches = before.MatchesPseudoElement(rect, "before");

bool valid = CssSelectorList.TryParse("rect:nonsense", out _); // false: unknown pseudo-classes are invalid

Properties

DefaultNamespace

Gets the default namespace URI, or null when none is declared.

public string? DefaultNamespace { get; }

Property Value

string

Prefixes

Gets the declared prefixes and their namespace URIs.

public IReadOnlyDictionary<string, string> Prefixes { get; }

Property Value

IReadOnlyDictionary<string, string>

Methods

Set(string?, string)

Declares a prefix, or the default namespace; a later declaration of the same prefix replaces an earlier one.

public void Set(string? prefix, string namespaceUri)

Parameters

prefix string

The prefix, or null for the default namespace.

namespaceUri string

The namespace URI. An empty string means no namespace.

TryGetNamespace(string, out string)

Looks up a prefix.

public bool TryGetNamespace(string prefix, out string namespaceUri)

Parameters

prefix string

The prefix.

namespaceUri string

The namespace URI when declared.

Returns

bool

True when the prefix is declared.