IniSyntaxTree Class
A parsed INI document.
public sealed class IniSyntaxTree : SyntaxTreeRemarks
Parsing never throws and never gives up: whatever the text says, the tree reproduces it exactly, and anything wrong with it is reported through IniSyntaxTree.GetDiagnostics.
Example
var tree = IniSyntaxTree.ParseText("[server]\nport = 8080\n");
var port = tree.GetRoot().GetValue("server", "port");
Assert.Equal("8080", port);- Inheritance
SyntaxTreeIniSyntaxTree
Properties
| Name | Description |
|---|---|
| FilePath | |
| Options | Gets the options the text was parsed with. |
FilePath
IniSyntaxTree.csOptions
IniSyntaxTree.csMethods
| Name | Description |
|---|---|
| Create(IniDocumentSyntax, IniParseOptions?, string?) | Creates a tree over root, taking its text from the root itself. |
| Create(IniDocumentSyntax, string?) | Creates a tree over root, taking its text and its options from the root itself. |
| GetChanges(IniSyntaxTree) | Describes how oldTree would have to change to become this one. |
| GetDiagnostics() | Gets every diagnostic in the tree, in source order. |
| GetRoot() | Gets the root of the tree. |
| GetText() | |
| IsEquivalentTo(IniSyntaxTree?) | Determines whether the two trees have the same structure and text, and are read with equal options. |
| IsEquivalentTo(SyntaxTree?) | Determines whether the two trees have the same structure and text, and are read with equal options. |
| ParseText(SourceText, IniParseOptions?, string?) | Parses text. |
| ParseText(SourceText, string?) | Parses text with IniParseOptions.Default. |
| ParseText(string, IniParseOptions?, string?) | Parses text. |
| ParseText(string, string?) | Parses text with IniParseOptions.Default. |
| WithChangedText(SourceText) | Returns a tree over newText, parsed with the same options. |
| WithChanges(TextChange[]) | Returns a tree over this text with changes applied. |
| WithChanges(IEnumerable<TextChange>) | Returns a tree over this text with changes applied. |
| WithRoot(IniDocumentSyntax) | Returns a tree whose root is root, read with the options of root. |
Create overloads
Create(IniDocumentSyntax, IniParseOptions?, string?)
IniSyntaxTree.csCreates a tree over root, taking its text from the root itself.
public static IniSyntaxTree Create(IniDocumentSyntax root, IniParseOptions? options, string? path = null)Parameters
rootIniDocumentSyntax- The root of the tree.
optionsIniParseOptions?- The options, or
nullfor theIniDocumentSyntax.Optionsofroot. pathstring?- Where the text came from, for the diagnostics to refer to.
Returns
Exceptions
ArgumentNullExceptionrootisnull.
Remarks
When options are those of root, the diagnostics are those it carries and the text is not parsed again. Other options read the text differently, so the text of root is parsed again with them, and the tree has the nodes and diagnostics they give; the annotations of root are not carried over then.
Create(IniDocumentSyntax, string?)
IniSyntaxTree.csCreates a tree over root, taking its text and its options from the root itself.
public static IniSyntaxTree Create(IniDocumentSyntax root, string? path = null)Parameters
rootIniDocumentSyntaxpathstring?
Returns
Exceptions
ArgumentNullExceptionrootisnull.
Remarks
The diagnostics are those root carries; the text is not parsed again.
GetChanges(IniSyntaxTree)
IniSyntaxTree.csDescribes how oldTree would have to change to become this one.
public IReadOnlyList<TextChange> GetChanges(IniSyntaxTree oldTree)GetDiagnostics()
IniSyntaxTree.csGets every diagnostic in the tree, in source order.
public override IReadOnlyList<Diagnostic> GetDiagnostics()Returns
GetRoot()
IniSyntaxTree.csGetText()
IniSyntaxTree.csIsEquivalentTo overloads
IsEquivalentTo(IniSyntaxTree?)
IniSyntaxTree.csDetermines whether the two trees have the same structure and text, and are read with equal options.
public bool IsEquivalentTo(IniSyntaxTree? other)Parameters
otherIniSyntaxTree?
Returns
Remarks
Trees read with different options can have the same text and structure, but not the same values.
IsEquivalentTo(SyntaxTree?)
IniSyntaxTree.csDetermines whether the two trees have the same structure and text, and are read with equal options.
public override bool IsEquivalentTo(SyntaxTree? other)Parameters
otherSyntaxTree?
Returns
Remarks
Trees read with different options can have the same text and structure, but not the same values.
ParseText overloads
ParseText(SourceText, IniParseOptions?, string?)
IniSyntaxTree.csParses text.
public static IniSyntaxTree ParseText(SourceText text, IniParseOptions? options, string? path = null)Parameters
textSourceTextoptionsIniParseOptions?pathstring?
Returns
Exceptions
ArgumentNullExceptiontextisnull.
ParseText(SourceText, string?)
IniSyntaxTree.csParses text with IniParseOptions.Default.
public static IniSyntaxTree ParseText(SourceText text, string? path = null)ParseText(string, IniParseOptions?, string?)
IniSyntaxTree.csParses text.
public static IniSyntaxTree ParseText(string text, IniParseOptions? options, string? path = null)Parameters
textstring- The INI document to read.
optionsIniParseOptions?- How to read it, or
nullforIniParseOptions.Default. pathstring?- Where the text came from, for the diagnostics to refer to.
Returns
Exceptions
ArgumentNullExceptiontextisnull.
ParseText(string, string?)
IniSyntaxTree.csParses text with IniParseOptions.Default.
public static IniSyntaxTree ParseText(string text, string? path = null)Parameters
textstring- The INI document to read.
pathstring?- Where the text came from, for the diagnostics to refer to.
Returns
Exceptions
ArgumentNullExceptiontextisnull.
WithChangedText(SourceText)
IniSyntaxTree.csReturns a tree over newText, parsed with the same options.
public IniSyntaxTree WithChangedText(SourceText newText)WithChanges overloads
WithChanges(TextChange[])
IniSyntaxTree.csReturns a tree over this text with changes applied.
public IniSyntaxTree WithChanges(params TextChange[] changes)WithChanges(IEnumerable<TextChange>)
IniSyntaxTree.csReturns a tree over this text with changes applied.
public IniSyntaxTree WithChanges(IEnumerable<TextChange> changes)WithRoot(IniDocumentSyntax)
IniSyntaxTree.csReturns a tree whose root is root, read with the options of root.
public IniSyntaxTree WithRoot(IniDocumentSyntax root)