Delen via


Document Class

Definition

Represents a source code document that is part of a project. It provides access to the source text, parsed syntax tree and the corresponding semantic model.

public ref class Document : Microsoft::CodeAnalysis::TextDocument
[System.Diagnostics.DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
public class Document : Microsoft.CodeAnalysis.TextDocument
[<System.Diagnostics.DebuggerDisplay("{GetDebuggerDisplay(),nq}")>]
type Document = class
    inherit TextDocument
Public Class Document
Inherits TextDocument
Inheritance
Document
Derived
Attributes

Properties

FilePath

The path to the document file or null if there is no document file.

(Inherited from TextDocument)
Folders

The sequence of logical folders the document is contained in.

(Inherited from TextDocument)
Id

The document's identifier. Many document instances may share the same ID, but only one document in a solution may have that ID.

(Inherited from TextDocument)
Name

The name of the document.

(Inherited from TextDocument)
Project

The project this document belongs to.

(Inherited from TextDocument)
SourceCodeKind

The kind of source code this document contains.

SupportsSemanticModel

true if this Document supports providing data through the GetSemanticModelAsync(CancellationToken) method.

If false then that method will return null instead.

SupportsSyntaxTree

true if this Document supports providing data through the GetSyntaxTreeAsync(CancellationToken) and GetSyntaxRootAsync(CancellationToken) methods.

If false then these methods will return null instead.

Methods

GetLinkedDocumentIds()

Gets the list of DocumentIds that are linked to this Document. Documents are considered to be linked if they share the same FilePath. This DocumentId is excluded from the result.

GetOptionsAsync(CancellationToken)

Returns the options that should be applied to this document. This consists of global options from Options, merged with any settings the user has specified at the document levels.

GetSemanticModelAsync(CancellationToken)

Gets the semantic model for this document asynchronously.

GetSyntaxRootAsync(CancellationToken)

Gets the root node of the syntax tree asynchronously.

GetSyntaxTreeAsync(CancellationToken)

Gets the SyntaxTree for this document asynchronously.

GetSyntaxVersionAsync(CancellationToken)

Gets the version of the syntax tree. This is generally the newer of the text version and the project's version.

GetTextAsync(CancellationToken)

Gets the current text for the document asynchronously.

(Inherited from TextDocument)
GetTextChangesAsync(Document, CancellationToken)

Get the text changes between this document and a prior version of the same document. The changes, when applied to the text of the old document, will produce the text of the current document.

GetTextVersionAsync(CancellationToken)

Gets the version of the document's text.

(Inherited from TextDocument)
TryGetSemanticModel(SemanticModel)

Gets the current semantic model for this document if the model is already computed and still cached. In almost all cases, you should call GetSemanticModelAsync(CancellationToken), which will compute the semantic model if necessary.

TryGetSyntaxRoot(SyntaxNode)

Gets the root node of the current syntax tree if the syntax tree has already been parsed and the tree is still cached. In almost all cases, you should call GetSyntaxRootAsync(CancellationToken) to fetch the root node, which will parse the document if necessary.

TryGetSyntaxTree(SyntaxTree)

Get the current syntax tree for the document if the text is already loaded and the tree is already parsed. In almost all cases, you should call GetSyntaxTreeAsync(CancellationToken) to fetch the tree, which will parse the tree if it's not already parsed.

TryGetSyntaxVersion(VersionStamp)

Get the current syntax tree version for the document if the text is already loaded and the tree is already parsed. In almost all cases, you should call GetSyntaxVersionAsync(CancellationToken) to fetch the version, which will load the tree if it's not already available.

TryGetText(SourceText)

Get the current text for the document if it is already loaded and available.

(Inherited from TextDocument)
TryGetTextVersion(VersionStamp)

Gets the version of the document's text if it is already loaded and available.

(Inherited from TextDocument)
WithFilePath(String)

Creates a new instance of this document updated to have the specified file path.

WithFolders(IEnumerable<String>)

Creates a new instance of this document updated to have the specified folders.

WithName(String)

Creates a new instance of this document updated to have the specified name.

WithSourceCodeKind(SourceCodeKind)

Creates a new instance of this document updated to have the source code kind specified.

WithSyntaxRoot(SyntaxNode)

Creates a new instance of this document updated to have a syntax tree rooted by the specified syntax node.

WithText(SourceText)

Creates a new instance of this document updated to have the text specified.

Applies to