/// <summary> /// Gets the workspace corresponding to the text buffer. /// </summary> public static Workspace GetWorkspace(this ITextBuffer buffer) { var container = buffer.AsTextContainer(); if (Workspace.TryGetWorkspace(container, out var workspace)) { return workspace; } return null; }
/// <summary> /// Gets the <see cref="Document"/>s from the corresponding <see cref="Workspace.CurrentSolution"/> that are associated with the <see cref="ITextBuffer"/>. /// There may be multiple <see cref="Document"/>s associated with the buffer if it is linked into multiple projects or is part of a Shared Project. /// </summary> public static IEnumerable<Document> GetRelatedDocuments(this ITextBuffer buffer) { return buffer.AsTextContainer().GetRelatedDocuments(); }
internal static bool CanApplyChangeDocumentToWorkspace(this ITextBuffer buffer) { Workspace workspace; if (Workspace.TryGetWorkspace(buffer.AsTextContainer(), out workspace)) { return workspace.CanApplyChange(ApplyChangesKind.ChangeDocument); } else { return false; } }
/// <summary> /// Returns the workspace or null /// </summary> /// <param name="buffer">Text buffer</param> /// <returns></returns> public static Workspace TryGetWorkspace(this ITextBuffer buffer) { Workspace ws; Workspace.TryGetWorkspace(buffer.AsTextContainer(), out ws); return ws; }