Click or drag to resize

Workspace Class



A workspace provides access to a active set of source code projects and documents and their associated syntax trees, compilations and semantic models. A workspace has a current solution that is an immutable snapshot of the projects and documents. This property may change over time as the workspace is updated either from live interactions in the environment or via call to the workspace's TryApplyChanges(Solution) method.
Inheritance Hierarchy

Namespace:  Microsoft.CodeAnalysis
Assembly:  Microsoft.CodeAnalysis.Workspaces (in Microsoft.CodeAnalysis.Workspaces.dll) Version: 2.3.0-dev-56735-00. Commit Hash: <developer build>
Syntax
public abstract class Workspace : IDisposable

The Workspace type exposes the following members.

Constructors
  NameDescription
Protected methodWorkspace
Constructs a new workspace instance.
Top
Properties
  NameDescription
Public propertyCanOpenDocuments
True if this workspace supports manually opening and closing documents.
Public propertyCurrentSolution
The current solution. The solution is an immutable model of the current set of projects and source documents. It provides access to source text, syntax trees and semantics. This property may change as the workspace reacts to changes in the environment or after TryApplyChanges(Solution) is called.
Public propertyKind
The kind of the workspace. This is generally Host if originating from the host environment, but may be any other name used for a specific kind of workspace.
Public propertyOptions
Gets or sets the set of all global options.
Protected propertyPartialSemanticsEnabled
Override this property if the workspace supports partial semantics for documents.
Public propertyServices
Services provider by the host for implementing workspace features.
Top
Methods
  NameDescription
Protected methodAdjustReloadedProject
Protected methodAdjustReloadedSolution
This method is called during OnSolutionReload. Override this method if you want to manipulate the reloaded solution.
Protected methodApplyAdditionalDocumentAdded
This method is called during TryApplyChanges(Solution) to add a new additional document to a project. Override this method to implement the capability of adding additional documents.
Protected methodApplyAdditionalDocumentRemoved
This method is called during TryApplyChanges(Solution) to remove an additional document from a project. Override this method to implement the capability of removing additional documents.
Protected methodApplyAdditionalDocumentTextChanged
This method is called to change the text of an additional document. Override this method to implement the capability of changing additional document text.
Protected methodApplyAnalyzerReferenceAdded
This method is called during TryApplyChanges(Solution) to add an analyzer reference to a project. Override this method to implement the capability of adding analyzer references.
Protected methodApplyAnalyzerReferenceRemoved
This method is called during TryApplyChanges(Solution) to remove an analyzer reference from a project. Override this method to implement the capability of removing analyzer references.
Protected methodApplyCompilationOptionsChanged
This method is called during TryApplyChanges(Solution) to change the compilation options. Override this method to implement the capability of changing compilation options.
Protected methodApplyDocumentAdded
This method is called during TryApplyChanges(Solution) to add a new document to a project. Override this method to implement the capability of adding documents.
Protected methodApplyDocumentInfoChanged
This method is called to change the info of a document. Override this method to implement the capability of changing a document's info.
Protected methodApplyDocumentRemoved
This method is called during TryApplyChanges(Solution) to remove a document from a project. Override this method to implement the capability of removing documents.
Protected methodApplyDocumentTextChanged
This method is called to change the text of a document. Override this method to implement the capability of changing document text.
Protected methodApplyMetadataReferenceAdded
This method is called during TryApplyChanges(Solution) to add a metadata reference to a project. Override this method to implement the capability of adding metadata references.
Protected methodApplyMetadataReferenceRemoved
This method is called during TryApplyChanges(Solution) to remove a metadata reference from a project. Override this method to implement the capability of removing metadata references.
Protected methodApplyParseOptionsChanged
This method is called during TryApplyChanges(Solution) to change the parse options. Override this method to implement the capability of changing parse options.
Protected methodApplyProjectAdded
This method is called during TryApplyChanges(Solution) to add a project to the current solution. Override this method to implement the capability of adding projects.
Protected methodApplyProjectChanges
This method is called during TryApplyChanges(Solution) for each project that has been added, removed or changed. Override this method if you want to modify how project changes are applied.
Protected methodApplyProjectReferenceAdded
This method is called during TryApplyChanges(Solution) to add a project reference to a project. Override this method to implement the capability of adding project references.
Protected methodApplyProjectReferenceRemoved
This method is called during TryApplyChanges(Solution) to remove a project reference from a project. Override this method to implement the capability of removing project references.
Protected methodApplyProjectRemoved
This method is called during TryApplyChanges(Solution) to remove a project from the current solution. Override this method to implement the capability of removing projects.
Public methodCanApplyChange
Determines if the specific kind of change is supported by the TryApplyChanges(Solution) method.
Protected methodCanApplyParseOptionChange
Protected methodCheckAdditionalDocumentIsInCurrentSolution
Throws an exception if an additional document is not part of the current solution.
Protected methodCheckAdditionalDocumentIsNotInCurrentSolution
Throws an exception if an additional document is already part of the current solution.
Protected methodCheckCanOpenDocuments
Protected methodCheckDocumentCanBeRemoved
Protected methodCheckDocumentIsClosed
Protected methodCheckDocumentIsInCurrentSolution
Throws an exception if a document is not part of the current solution.
Protected methodCheckDocumentIsNotInCurrentSolution
Throws an exception if a document is already part of the current solution.
Protected methodCheckDocumentIsOpen
Protected methodCheckProjectCanBeRemoved
Currently projects can always be removed, but this method still exists because it's protected and we don't want to break people who may have derived from Workspace and either called it, or overridden it.
Protected methodCheckProjectDoesNotContainOpenDocuments
Protected methodCheckProjectDoesNotHaveAnalyzerReference
Throws an exception if a project already has a specific analyzer reference.
Protected methodCheckProjectDoesNotHaveMetadataReference
Throws an exception if a project already has a specific metadata reference.
Protected methodCheckProjectDoesNotHaveProjectReference
Throws an exception if a project already has a specific project reference.
Protected methodCheckProjectDoesNotHaveTransitiveProjectReference
Throws an exception if project has a transitive reference to another project.
Protected methodCheckProjectHasAnalyzerReference
Throws an exception if a project does not have a specific analyzer reference.
Protected methodCheckProjectHasMetadataReference
Throws an exception if a project does not have a specific metadata reference.
Protected methodCheckProjectHasProjectReference
Throws an exception if a project does not have a specific project reference.
Protected methodCheckProjectIsInCurrentSolution
Throws an exception if the project is not part of the current solution.
Protected methodCheckProjectIsNotInCurrentSolution
Throws an exception is the project is part of the current solution.
Protected methodCheckSolutionIsEmpty
Throws an exception is the solution is not empty.
Protected methodClearDocumentData
This method is called to clear an individual document is removed. Override this method if you want to do additional work when a document is removed. Call the base method at the end of your method.
Protected methodClearOpenDocument
Protected methodClearProjectData
This method is called when an individual project is removed. Override this method if you want to do additional work when a project is removed. Call the base method at the end of your method.
Protected methodClearSolution
Clears all solution data and empties the current solution.
Protected methodClearSolutionData
This method is called when a solution is cleared. Override this method if you want to do additional work when a solution is cleared. Call the base method at the end of your method.
Public methodCloseAdditionalDocument
Close the specified additional document in the host environment.
Public methodCloseDocument
Close the specified document in the host environment.
Protected methodCreateSolution(SolutionId)
Create a new empty solution instance associated with this workspace.
Protected methodCreateSolution(SolutionInfo)
Create a new empty solution instance associated with this workspace.
Public methodDispose
Disposes this workspace. The workspace can longer be used after it is disposed.
Protected methodDispose(Boolean)
Call this method when the workspace is disposed. Override this method to do addition work when the workspace is disposed. Call this method at the end of your method.
Protected methodGetAdditionalDocumentName
Gets the name to use for an additional document in an error message.
Public methodGetDocumentIdInCurrentContext
Gets the id for the document associated with the given text container in its current context. Documents are normally associated with a text container when the documents are opened.
Protected methodGetDocumentName
Gets the name to use for a document in an error message.
Public methodGetOpenDocumentIds
Protected methodGetProjectName
Gets the name to use for a project in an error message.
Public methodGetRelatedDocumentIds
Public methodStatic memberGetWorkspaceRegistration
Returns a WorkspaceRegistration for a given text container.
Public methodIsDocumentOpen
Determines if the document is currently open in the host environment.
Protected methodOnAdditionalDocumentAdded
Call this method when an additional document is added to a project in the host environment.
Protected methodOnAdditionalDocumentClosed
Protected methodOnAdditionalDocumentOpened
Protected methodOnAdditionalDocumentRemoved
Call this method when an additional document is removed from a project in the host environment.
Protected methodOnAdditionalDocumentTextChanged
Call this method when the text of a document is updated in the host environment.
Protected methodOnAdditionalDocumentTextLoaderChanged
Call this method when the text of a document is changed on disk.
Protected methodOnAnalyzerReferenceAdded
Call this method when an analyzer reference is added to a project in the host environment.
Protected methodOnAnalyzerReferenceRemoved
Call this method when an analyzer reference is removed from a project in the host environment.
Protected methodOnAssemblyNameChanged
Call this method when a project's assembly name is changed in the host environment.
Protected methodOnCompilationOptionsChanged
Call this method when a project's compilation options are changed in the host environment.
Protected methodOnDocumentAdded
Call this method when a document is added to a project in the host environment.
Protected methodOnDocumentClosed
Protected methodOnDocumentClosing
Override this method to act immediately when a document is closing, as opposed to waiting for the corresponding workspace changed event to fire asynchronously.
Protected methodOnDocumentContextUpdated
Protected methodOnDocumentInfoChanged
Call this method when the document info changes, such as the name, folders or file path.
Protected methodOnDocumentOpened
Protected methodOnDocumentReloaded
Call this method when a document is reloaded in the host environment.
Protected methodOnDocumentRemoved
Call this method when a document is removed from a project in the host environment.
Protected methodOnDocumentSourceCodeKindChanged
Call this method when the SourceCodeKind of a document changes in the host environment.
Protected methodOnDocumentTextChanged(Document)
Override this method to act immediately when the text of a document has changed, as opposed to waiting for the corresponding workspace changed event to fire asynchronously.
Protected methodOnDocumentTextChanged(DocumentId, SourceText, PreservationMode)
Call this method when the text of a document is updated in the host environment.
Protected methodOnDocumentTextLoaderChanged
Call this method when the text of a document is changed on disk.
Protected methodOnMetadataReferenceAdded
Call this method when a metadata reference is added to a project in the host environment.
Protected methodOnMetadataReferenceRemoved
Call this method when a metadata reference is removed from a project in the host environment.
Protected methodOnOutputFilePathChanged
Call this method when a project's output file path is changed in the host environment.
Protected methodOnParseOptionsChanged
Call this method when a project's parse options are changed in the host environment.
Protected methodOnProjectAdded
Call this method to respond to a project being added/opened in the host environment.
Protected methodOnProjectNameChanged
Call this method when a project's name is changed in the host environment.
Protected methodOnProjectReferenceAdded
Call this method when a project reference is added to a project in the host environment.
Protected methodOnProjectReferenceRemoved
Call this method when a project reference is removed from a project in the host environment.
Protected methodOnProjectReloaded
Call this method to respond to a project being reloaded in the host environment.
Protected methodOnProjectRemoved
Call this method to respond to a project being removed from the host environment.
Protected methodOnSolutionAdded
Call this method to respond to a solution being opened in the host environment.
Protected methodOnSolutionReloaded
Call this method to respond to a solution being reloaded in the host environment.
Protected methodOnSolutionRemoved
This method is called when the solution is removed from the workspace. Override this method if you want to do additional work when the solution is removed. Call the base method at the end of your method. Call this method to respond to a solution being removed/cleared/closed in the host environment.
Protected methodOnWorkspaceFailed
Public methodOpenAdditionalDocument
Open the specified additional document in the host environment.
Public methodOpenDocument
Open the specified document in the host environment.
Protected methodRaiseDocumentActiveContextChangedEventAsync(Document) Obsolete.
Protected methodRaiseDocumentActiveContextChangedEventAsync(SourceTextContainer, DocumentId, DocumentId)
Protected methodRaiseDocumentClosedEventAsync
Protected methodRaiseDocumentOpenedEventAsync
Protected methodRaiseWorkspaceChangedEventAsync
Protected methodRegisterText
Register a correspondence between a text container and a workspace.
Protected methodScheduleTask(Action, String)
Executes an action as a background task, as part of a sequential queue of tasks.
Protected methodScheduleTaskT(Void, T)
Protected methodSetCurrentSolution
Sets the CurrentSolution of this workspace. This method does not raise a WorkspaceChanged event.
Public methodTryApplyChanges
Apply changes made to a solution back to the workspace. The specified solution must be one that originated from this workspace. If it is not, or the workspace has been updated since the solution was obtained from the workspace, then this method returns false. This method will still throw if the solution contains changes that are not supported according to the CanApplyChange(ApplyChangesKind) method.
Public methodStatic memberTryGetWorkspace
Gets the workspace associated with the specific text container.
Protected methodUnregisterText
Unregister a correspondence between a text container and a workspace.
Protected methodUpdateReferencesAfterAdd
Updates all projects to properly reference other projects as project references instead of metadata references.
Top
Events
  NameDescription
Public eventDocumentActiveContextChanged
An event that is fired when the active context document associated with a buffer changes.
Public eventDocumentClosed
An event that is fired when a document is closed in the editor.
Public eventDocumentOpened
An event that is fired when a documents is opened in the editor.
Public eventWorkspaceChanged
An event raised whenever the current solution is changed.
Public eventWorkspaceFailed
An event raised whenever the workspace or part of its solution model fails to access a file or other external resource.
Top
See Also