SyntaxFactory Class
Builds TOML nodes, tokens, and trivia.
public static class SyntaxFactoryRemarks
A node built here is not part of any document, so its span starts at zero. Putting it into a tree with SyntaxNodeExtensions.ReplaceNode gives it a real position, without re-reading any text.
The methods that take .NET values write them the way TOML requires: keys are quoted when they cannot be bare, strings are escaped, and floats always read back as floats. The ones that take tokens use them as they are.
Properties
| Name | Description |
|---|---|
| CarriageReturnLineFeed | A Windows line break. |
| LineFeed | A Unix line break. |
| Space | A single space. |
| Tab | A single tab. |
CarriageReturnLineFeed
SyntaxFactory.csLineFeed
SyntaxFactory.csSpace
SyntaxFactory.csMethods
| Name | Description |
|---|---|
| AreEquivalent(TomlSyntaxNode?, TomlSyntaxNode?) | Determines whether the two nodes have the same structure and text. |
| BadToken(string) | Creates a token holding text the parser could make no sense of. |
| Comment(string) | Creates comment trivia. |
| EndOfLine(string) | Creates a line break: \n or \r\n, the only two TOML has. |
| Key(SyntaxTokenList) | Creates a key from its parts and the dots between them. |
| Key(string[]) | Creates a key from the names of its parts, quoting each that cannot be bare. |
| KeyPart(string) | Creates one part of a key: a bare key when name can be one, a basic string otherwise. |
| List<TNode>() | |
| List<TNode>(IEnumerable<TNode>) | |
| Literal(bool) | Creates true or false. |
| Literal(DateOnly) | Creates a local date token, such as 1979-05-27. |
| Literal(DateTime) | Creates a local date-time token, such as 1979-05-27T07:32:00. The kind of value is ignored. |
| Literal(DateTimeOffset) | Creates an offset date-time token, such as 1979-05-27T07:32:00Z. |
| Literal(double) | Creates a float token, written so that it reads back as the same float. |
| Literal(long) | Creates an integer token, written in decimal. |
| Literal(string) | Creates a basic string token holding value, escaped as TOML requires. |
| Literal(TimeOnly) | Creates a local time token, such as 07:32:00. |
| MissingToken(SyntaxKind) | Creates a zero-width token standing in for one the text does not have. |
| ParseDocument(string, TomlParseOptions?) | Parses text and returns its root. |
| ParseSyntaxTree(string, TomlParseOptions?, string?) | Parses text into a tree. |
| ParseValue(string, TomlParseOptions?) | Parses text as a single value, such as [1, 2] or '''literal'''. |
| SeparatedList<TNode>() | |
| SeparatedList<TNode>(IEnumerable<SyntaxNodeOrToken>) | Creates a list from nodes and the separators to put between them. |
| SeparatedList<TNode>(IEnumerable<TNode>) | Creates a list of nodes with a comma and a space between each pair. |
| SingletonList<TNode>(TNode) | |
| SingletonSeparatedList<TNode>(TNode) | |
| Token(SyntaxTriviaList, SyntaxKind, SyntaxTriviaList) | Creates a token whose text is fixed by its kind, with trivia on either side. |
| Token(SyntaxKind) | Creates a token whose text is fixed by its kind, such as a bracket or true. |
| TokenList() | |
| TokenList(SyntaxToken) | |
| TokenList(SyntaxToken[]) | |
| TokenList(IEnumerable<SyntaxToken>) | |
| TomlArray(SeparatedSyntaxList<TomlValueSyntax>) | |
| TomlArray(SyntaxToken, SeparatedSyntaxList<TomlValueSyntax>, SyntaxToken) | |
| TomlArray(TomlValueSyntax[]) | Creates an array such as [1, 2, 3]. |
| TomlArrayOfTables(string[]) | Creates an array-of-tables header such as [[products]]. |
| TomlBoolean(SyntaxToken) | |
| TomlBoolean(bool) | |
| TomlDateTime(SyntaxToken) | Creates a date, a time, or both, taking the kind of the node from the token. |
| TomlDateTime(DateOnly) | |
| TomlDateTime(DateTime) | |
| TomlDateTime(DateTimeOffset) | |
| TomlDateTime(TimeOnly) | |
| TomlDocument(SyntaxList<TomlEntrySyntax>, SyntaxToken) | Creates a document from entries. |
| TomlDocument(TomlEntrySyntax[]) | Creates a document from entries, ending the line of each that does not end its own. |
| TomlFloat(SyntaxToken) | |
| TomlFloat(double) | |
| TomlInlineTable(SeparatedSyntaxList<TomlPropertySyntax>) | Creates an inline table with a space inside each brace, or {} when it is empty. |
| TomlInlineTable(SyntaxToken, SeparatedSyntaxList<TomlPropertySyntax>, SyntaxToken) | |
| TomlInlineTable(TomlPropertySyntax[]) | Creates an inline table such as { x = 1, y = 2 }. |
| TomlInteger(SyntaxToken) | |
| TomlInteger(long) | |
| TomlProperty(TomlKeySyntax, SyntaxToken, TomlValueSyntax) | |
| TomlProperty(TomlKeySyntax, TomlValueSyntax) | Creates key = value. |
| TomlProperty(string, TomlValueSyntax) | Creates name = value, quoting name when it cannot be a bare key. |
| TomlSkippedText(SyntaxTokenList) | |
| TomlSkippedText(string) | |
| TomlSkippedValue(SyntaxTokenList) | Creates a value that holds tokens as they are, or a missing value when there are none. |
| TomlString(SyntaxToken) | Creates a string from a token of any of the four string kinds. |
| TomlString(string) | Creates a basic string holding value, escaped as TOML requires. |
| TomlTable(SyntaxToken, TomlKeySyntax, SyntaxToken) | Creates a table header, or an array-of-tables header when openBracketToken is [[. |
| TomlTable(string[]) | Creates a table header such as [server], or [server.http] from several names. |
| Trivia(SyntaxKind, string) | Creates trivia of any kind, with text used as it is. |
| TriviaList() | |
| TriviaList(SyntaxTrivia) | |
| TriviaList(SyntaxTrivia[]) | |
| TriviaList(IEnumerable<SyntaxTrivia>) | |
| Whitespace(string) | Creates whitespace trivia: one or more spaces and tabs, the only whitespace TOML has. |
AreEquivalent(TomlSyntaxNode?, TomlSyntaxNode?)
SyntaxFactory.csDetermines whether the two nodes have the same structure and text.
public static bool AreEquivalent(TomlSyntaxNode? oldNode, TomlSyntaxNode? newNode)BadToken(string)
SyntaxFactory.csCreates a token holding text the parser could make no sense of.
public static SyntaxToken BadToken(string text)Comment(string)
SyntaxFactory.csCreates comment trivia.
public static SyntaxTrivia Comment(string text)Parameters
textstring
Returns
Exceptions
ArgumentNullExceptiontextisnull.ArgumentExceptiontextis not a TOML comment: it does not start with#, or it holds a line break, a control character other than tab, or a lone surrogate.
EndOfLine(string)
SyntaxFactory.csCreates a line break: \n or \r\n, the only two TOML has.
public static SyntaxTrivia EndOfLine(string text)Parameters
textstring
Returns
Exceptions
ArgumentNullExceptiontextisnull.ArgumentExceptiontextis neither\nnor\r\n.
Key overloads
Key(SyntaxTokenList)
SyntaxFactory.csCreates a key from its parts and the dots between them.
public static TomlKeySyntax Key(SyntaxTokenList tokens)Key(string[])
SyntaxFactory.csCreates a key from the names of its parts, quoting each that cannot be bare.
public static TomlKeySyntax Key(params string[] names)Parameters
namesstring[]
Returns
Exceptions
ArgumentNullExceptionnamesor one of its items isnull.ArgumentExceptionnamesis empty.
Example
Key("site", "google.com") is site."google.com".
KeyPart(string)
SyntaxFactory.csCreates one part of a key: a bare key when name can be one, a basic string otherwise.
public static SyntaxToken KeyPart(string name)Parameters
namestring
Returns
Exceptions
ArgumentNullExceptionnameisnull.ArgumentExceptionnameholds a lone surrogate, which TOML cannot represent.
List overloads
List<TNode>()
SyntaxFactory.cspublic static SyntaxList<TNode> List<TNode>() where TNode : TomlSyntaxNodeNo documentation is available.
List<TNode>(IEnumerable<TNode>)
SyntaxFactory.cspublic static SyntaxList<TNode> List<TNode>(IEnumerable<TNode> nodes) where TNode : TomlSyntaxNodeType parameters
TNode
Parameters
nodesIEnumerable<TNode>
Returns
Exceptions
ArgumentNullExceptionnodesisnull.
Literal overloads
Literal(bool)
SyntaxFactory.csCreates true or false.
public static SyntaxToken Literal(bool value)Literal(DateOnly)
SyntaxFactory.csCreates a local date token, such as 1979-05-27.
public static SyntaxToken Literal(DateOnly value)Literal(DateTime)
SyntaxFactory.csCreates a local date-time token, such as 1979-05-27T07:32:00. The kind of value is ignored.
public static SyntaxToken Literal(DateTime value)Literal(DateTimeOffset)
SyntaxFactory.csCreates an offset date-time token, such as 1979-05-27T07:32:00Z.
public static SyntaxToken Literal(DateTimeOffset value)Literal(double)
SyntaxFactory.csCreates a float token, written so that it reads back as the same float.
public static SyntaxToken Literal(double value)Literal(long)
SyntaxFactory.csCreates an integer token, written in decimal.
public static SyntaxToken Literal(long value)Literal(string)
SyntaxFactory.csCreates a basic string token holding value, escaped as TOML requires.
public static SyntaxToken Literal(string value)Parameters
valuestring
Returns
Exceptions
ArgumentNullExceptionvalueisnull.ArgumentExceptionvalueholds a lone surrogate, a character TOML cannot hold, escaped or not.
Literal(TimeOnly)
SyntaxFactory.csCreates a local time token, such as 07:32:00.
public static SyntaxToken Literal(TimeOnly value)MissingToken(SyntaxKind)
SyntaxFactory.csCreates a zero-width token standing in for one the text does not have.
public static SyntaxToken MissingToken(SyntaxKind kind)ParseDocument(string, TomlParseOptions?)
SyntaxFactory.csParses text and returns its root.
public static TomlDocumentSyntax ParseDocument(string text, TomlParseOptions? options = null)ParseSyntaxTree(string, TomlParseOptions?, string?)
SyntaxFactory.csParses text into a tree.
public static TomlSyntaxTree ParseSyntaxTree(string text, TomlParseOptions? options = null, string? path = null)Parameters
textstringoptionsTomlParseOptions?pathstring?
Returns
Exceptions
ArgumentNullExceptiontextisnull.
ParseValue(string, TomlParseOptions?)
SyntaxFactory.csParses text as a single value, such as [1, 2] or '''literal'''.
public static TomlValueSyntax ParseValue(string text, TomlParseOptions? options = null)Parameters
textstringoptionsTomlParseOptions?
Returns
Exceptions
ArgumentNullExceptiontextisnull.
Remarks
Text after the value makes the whole of it a TomlSkippedValueSyntax. Whether text held one value the grammar accepts and nothing else is what SyntaxNode.ContainsDiagnostics says. A key defined twice in an inline table is not a grammar mistake: TomlSyntaxTree.GetDiagnostics reports it once the value is part of a document.
SeparatedList overloads
SeparatedList<TNode>()
SyntaxFactory.cspublic static SeparatedSyntaxList<TNode> SeparatedList<TNode>() where TNode : TomlSyntaxNodeNo documentation is available.
SeparatedList<TNode>(IEnumerable<SyntaxNodeOrToken>)
SyntaxFactory.csCreates a list from nodes and the separators to put between them.
public static SeparatedSyntaxList<TNode> SeparatedList<TNode>(IEnumerable<SyntaxNodeOrToken> nodesAndSeparators) where TNode : TomlSyntaxNodeType parameters
TNode
Parameters
nodesAndSeparatorsIEnumerable<SyntaxNodeOrToken>
Returns
Exceptions
ArgumentNullExceptionnodesAndSeparatorsisnull.
SeparatedList<TNode>(IEnumerable<TNode>)
SyntaxFactory.csCreates a list of nodes with a comma and a space between each pair.
public static SeparatedSyntaxList<TNode> SeparatedList<TNode>(IEnumerable<TNode> nodes) where TNode : TomlSyntaxNodeType parameters
TNode
Parameters
nodesIEnumerable<TNode>
Returns
Exceptions
ArgumentNullExceptionnodesor one of its items isnull.
Remarks
A node that ends with a comment, such as one from SyntaxFactory.ParseValue, gets a line break after it, or the comment would hide the comma or the bracket that follows it.
SingletonList<TNode>(TNode)
SyntaxFactory.cspublic static SyntaxList<TNode> SingletonList<TNode>(TNode node) where TNode : TomlSyntaxNodeNo documentation is available.
SingletonSeparatedList<TNode>(TNode)
SyntaxFactory.cspublic static SeparatedSyntaxList<TNode> SingletonSeparatedList<TNode>(TNode node) where TNode : TomlSyntaxNodeNo documentation is available.
Token overloads
Token(SyntaxTriviaList, SyntaxKind, SyntaxTriviaList)
SyntaxFactory.csCreates a token whose text is fixed by its kind, with trivia on either side.
public static SyntaxToken Token(SyntaxTriviaList leading, SyntaxKind kind, SyntaxTriviaList trailing)Parameters
leadingSyntaxTriviaListkindSyntaxKindtrailingSyntaxTriviaList
Returns
Exceptions
ArgumentExceptionkindis not a token whose text is fixed, such as a key or a value.
Token(SyntaxKind)
SyntaxFactory.csCreates a token whose text is fixed by its kind, such as a bracket or true.
public static SyntaxToken Token(SyntaxKind kind)Parameters
kindSyntaxKind
Returns
Exceptions
ArgumentExceptionkindis not a token whose text is fixed, such as a key or a value.
TokenList overloads
TokenList()
SyntaxFactory.csTokenList(SyntaxToken)
SyntaxFactory.cspublic static SyntaxTokenList TokenList(SyntaxToken token)No documentation is available.
TokenList(SyntaxToken[])
SyntaxFactory.cspublic static SyntaxTokenList TokenList(params SyntaxToken[] tokens)No documentation is available.
TokenList(IEnumerable<SyntaxToken>)
SyntaxFactory.cspublic static SyntaxTokenList TokenList(IEnumerable<SyntaxToken> tokens)TomlArray overloads
TomlArray(SeparatedSyntaxList<TomlValueSyntax>)
SyntaxFactory.cspublic static TomlArraySyntax TomlArray(SeparatedSyntaxList<TomlValueSyntax> elements)No documentation is available.
TomlArray(SyntaxToken, SeparatedSyntaxList<TomlValueSyntax>, SyntaxToken)
SyntaxFactory.cspublic static TomlArraySyntax TomlArray(SyntaxToken openBracketToken, SeparatedSyntaxList<TomlValueSyntax> elements, SyntaxToken closeBracketToken)Parameters
openBracketTokenSyntaxTokenelementsSeparatedSyntaxList<TomlValueSyntax>closeBracketTokenSyntaxToken
Returns
No documentation is available.
TomlArray(TomlValueSyntax[])
SyntaxFactory.csCreates an array such as [1, 2, 3].
public static TomlArraySyntax TomlArray(params TomlValueSyntax[] values)TomlArrayOfTables(string[])
SyntaxFactory.csCreates an array-of-tables header such as [[products]].
public static TomlTableSyntax TomlArrayOfTables(params string[] names)Parameters
namesstring[]
Returns
Exceptions
ArgumentNullExceptionnamesisnull.ArgumentExceptionnamesis empty.
TomlBoolean overloads
TomlBoolean(SyntaxToken)
SyntaxFactory.cspublic static TomlBooleanSyntax TomlBoolean(SyntaxToken booleanToken)Parameters
booleanTokenSyntaxToken
Returns
Exceptions
ArgumentExceptionbooleanTokenis neithertruenorfalse.
TomlBoolean(bool)
SyntaxFactory.cspublic static TomlBooleanSyntax TomlBoolean(bool value)No documentation is available.
TomlDateTime overloads
TomlDateTime(SyntaxToken)
SyntaxFactory.csCreates a date, a time, or both, taking the kind of the node from the token.
public static TomlDateTimeSyntax TomlDateTime(SyntaxToken dateTimeToken)Parameters
dateTimeTokenSyntaxToken
Returns
Exceptions
ArgumentExceptiondateTimeTokenis not a date or a time.
TomlDateTime(DateOnly)
SyntaxFactory.cspublic static TomlDateTimeSyntax TomlDateTime(DateOnly value)No documentation is available.
TomlDateTime(DateTime)
SyntaxFactory.cspublic static TomlDateTimeSyntax TomlDateTime(DateTime value)No documentation is available.
TomlDateTime(DateTimeOffset)
SyntaxFactory.cspublic static TomlDateTimeSyntax TomlDateTime(DateTimeOffset value)No documentation is available.
TomlDateTime(TimeOnly)
SyntaxFactory.cspublic static TomlDateTimeSyntax TomlDateTime(TimeOnly value)No documentation is available.
TomlDocument overloads
TomlDocument(SyntaxList<TomlEntrySyntax>, SyntaxToken)
SyntaxFactory.csCreates a document from entries.
public static TomlDocumentSyntax TomlDocument(SyntaxList<TomlEntrySyntax> entries, SyntaxToken endOfFileToken)Parameters
entriesSyntaxList<TomlEntrySyntax>endOfFileTokenSyntaxToken
Returns
Remarks
An entry followed by another one on the same line gets a line break after it, and so does a comment in front of an entry, or the text would read as something else. The last entry is left as it is.
TomlDocument(TomlEntrySyntax[])
SyntaxFactory.csCreates a document from entries, ending the line of each that does not end its own.
public static TomlDocumentSyntax TomlDocument(params TomlEntrySyntax[] entries)TomlFloat overloads
TomlFloat(SyntaxToken)
SyntaxFactory.cspublic static TomlFloatSyntax TomlFloat(SyntaxToken floatToken)TomlFloat(double)
SyntaxFactory.cspublic static TomlFloatSyntax TomlFloat(double value)No documentation is available.
TomlInlineTable overloads
TomlInlineTable(SeparatedSyntaxList<TomlPropertySyntax>)
SyntaxFactory.csCreates an inline table with a space inside each brace, or {} when it is empty.
public static TomlInlineTableSyntax TomlInlineTable(SeparatedSyntaxList<TomlPropertySyntax> properties)TomlInlineTable(SyntaxToken, SeparatedSyntaxList<TomlPropertySyntax>, SyntaxToken)
SyntaxFactory.cspublic static TomlInlineTableSyntax TomlInlineTable(SyntaxToken openBraceToken, SeparatedSyntaxList<TomlPropertySyntax> properties, SyntaxToken closeBraceToken)Parameters
openBraceTokenSyntaxTokenpropertiesSeparatedSyntaxList<TomlPropertySyntax>closeBraceTokenSyntaxToken
Returns
No documentation is available.
TomlInlineTable(TomlPropertySyntax[])
SyntaxFactory.csCreates an inline table such as { x = 1, y = 2 }.
public static TomlInlineTableSyntax TomlInlineTable(params TomlPropertySyntax[] properties)TomlInteger overloads
TomlInteger(SyntaxToken)
SyntaxFactory.cspublic static TomlIntegerSyntax TomlInteger(SyntaxToken integerToken)TomlInteger(long)
SyntaxFactory.cspublic static TomlIntegerSyntax TomlInteger(long value)No documentation is available.
TomlProperty overloads
TomlProperty(TomlKeySyntax, SyntaxToken, TomlValueSyntax)
SyntaxFactory.cspublic static TomlPropertySyntax TomlProperty(TomlKeySyntax key, SyntaxToken equalsToken, TomlValueSyntax value)Parameters
keyTomlKeySyntaxequalsTokenSyntaxTokenvalueTomlValueSyntax
Returns
Exceptions
ArgumentNullExceptionkeyorvalueisnull.ArgumentExceptionvaluestarts with a line break or a comment, which would put it on a line of its own.
TomlProperty(TomlKeySyntax, TomlValueSyntax)
SyntaxFactory.csCreates key = value.
public static TomlPropertySyntax TomlProperty(TomlKeySyntax key, TomlValueSyntax value)Parameters
keyTomlKeySyntaxvalueTomlValueSyntax
Returns
Exceptions
ArgumentNullExceptionkeyorvalueisnull.ArgumentExceptionvaluestarts with a line break or a comment, which would put it on a line of its own.
TomlProperty(string, TomlValueSyntax)
SyntaxFactory.csCreates name = value, quoting name when it cannot be a bare key.
public static TomlPropertySyntax TomlProperty(string name, TomlValueSyntax value)Parameters
namestringvalueTomlValueSyntax
Returns
Exceptions
ArgumentNullExceptionnameorvalueisnull.
Remarks
name is one name, even if it has dots in it. Use SyntaxFactory.Key for a dotted key.
TomlSkippedText overloads
TomlSkippedText(SyntaxTokenList)
SyntaxFactory.cspublic static TomlSkippedTextSyntax TomlSkippedText(SyntaxTokenList tokens)No documentation is available.
TomlSkippedText(string)
SyntaxFactory.cspublic static TomlSkippedTextSyntax TomlSkippedText(string text)TomlSkippedValue(SyntaxTokenList)
SyntaxFactory.csCreates a value that holds tokens as they are, or a missing value when there are none.
public static TomlSkippedValueSyntax TomlSkippedValue(SyntaxTokenList tokens)TomlString overloads
TomlString(SyntaxToken)
SyntaxFactory.csCreates a string from a token of any of the four string kinds.
public static TomlStringSyntax TomlString(SyntaxToken stringToken)TomlString(string)
SyntaxFactory.csCreates a basic string holding value, escaped as TOML requires.
public static TomlStringSyntax TomlString(string value)TomlTable overloads
TomlTable(SyntaxToken, TomlKeySyntax, SyntaxToken)
SyntaxFactory.csCreates a table header, or an array-of-tables header when openBracketToken is [[.
public static TomlTableSyntax TomlTable(SyntaxToken openBracketToken, TomlKeySyntax key, SyntaxToken closeBracketToken)Parameters
openBracketTokenSyntaxTokenkeyTomlKeySyntaxcloseBracketTokenSyntaxToken
Returns
Exceptions
ArgumentNullExceptionkeyisnull.
TomlTable(string[])
SyntaxFactory.csCreates a table header such as [server], or [server.http] from several names.
public static TomlTableSyntax TomlTable(params string[] names)Parameters
namesstring[]
Returns
Exceptions
ArgumentNullExceptionnamesisnull.ArgumentExceptionnamesis empty.
Trivia(SyntaxKind, string)
SyntaxFactory.csCreates trivia of any kind, with text used as it is.
public static SyntaxTrivia Trivia(SyntaxKind kind, string text)Parameters
kindSyntaxKindtextstring
Returns
Exceptions
ArgumentNullExceptiontextisnull.
Remarks
Nothing checks that text is what kind says, which is what lets a tree hold exactly what a document has, mistakes included. Prefer SyntaxFactory.Whitespace, SyntaxFactory.EndOfLine, and SyntaxFactory.Comment, which refuse text that would change what the tokens around it mean.
TriviaList overloads
TriviaList()
SyntaxFactory.csTriviaList(SyntaxTrivia)
SyntaxFactory.cspublic static SyntaxTriviaList TriviaList(SyntaxTrivia trivia)No documentation is available.
TriviaList(SyntaxTrivia[])
SyntaxFactory.cspublic static SyntaxTriviaList TriviaList(params SyntaxTrivia[] trivia)No documentation is available.
TriviaList(IEnumerable<SyntaxTrivia>)
SyntaxFactory.cspublic static SyntaxTriviaList TriviaList(IEnumerable<SyntaxTrivia> trivia)Whitespace(string)
SyntaxFactory.csCreates whitespace trivia: one or more spaces and tabs, the only whitespace TOML has.
public static SyntaxTrivia Whitespace(string text)Parameters
textstring
Returns
Exceptions
ArgumentNullExceptiontextisnull.ArgumentExceptiontextis empty, or holds something other than spaces and tabs.