SyntaxFacts Class

Answers questions about a SyntaxKind that do not need a node to ask them of.

public static class SyntaxFacts

Methods

NameDescription
GetText(SyntaxKind)Returns the text a kind is always spelled with, or an empty string when its text varies.
IsNameCharacter(Rune)Determines whether value may appear inside an XML name.
IsNameStartCharacter(Rune)Determines whether value may begin an XML name.
IsTrivia(SyntaxKind)Determines whether kind is whitespace, a line break, or text skipped inside a tag.
IsWhitespace(char)Determines whether value is whitespace as XML defines it.

GetText(SyntaxKind)

SyntaxFacts.cs

Returns the text a kind is always spelled with, or an empty string when its text varies.

public static string GetText(SyntaxKind kind)

Parameters

kind SyntaxKind

Returns

string

Remarks

This is the canonical spelling, and the only one XML allows. The parser still reads <?XML or <!doctype as the construct they were meant to be, reporting the spelling, and the token then carries what the document said; a token built from a kind alone gets the spelling here.

IsNameCharacter(Rune)

SyntaxFacts.cs

Determines whether value may appear inside an XML name.

public static bool IsNameCharacter(Rune value)

Parameters

value Rune

Returns

bool

Remarks

This is the NameChar production of XML 1.0: everything a name may begin with, plus the characters that may only follow -- a digit, a hyphen, a full stop, the middle dot, and the combining marks.

IsNameStartCharacter(Rune)

SyntaxFacts.cs

Determines whether value may begin an XML name.

public static bool IsNameStartCharacter(Rune value)

Parameters

value Rune

Returns

bool

Remarks

This is the NameStartChar production of XML 1.0 verbatim. It is not the same set as "a Unicode letter": it excludes some letters, such as ª and µ, and includes characters that are not letters at all. It takes a scalar value rather than a Char because a name character may sit outside the basic plane, where it is written as a surrogate pair that means nothing one half at a time.

IsTrivia(SyntaxKind)

SyntaxFacts.cs

Determines whether kind is whitespace, a line break, or text skipped inside a tag.

public static bool IsTrivia(SyntaxKind kind)

Parameters

kind SyntaxKind

Returns

bool

IsWhitespace(char)

SyntaxFacts.cs

Determines whether value is whitespace as XML defines it.

public static bool IsWhitespace(char value)

Parameters

value char

Returns

bool

Remarks

This is the S production: a space, a tab, a carriage return, or a line feed. It is much narrower than Char.IsWhiteSpace, which also accepts characters such as a no-break space.