本文整理汇总了C#中Document.GetTextDocument方法的典型用法代码示例。如果您正苦于以下问题:C# Document.GetTextDocument方法的具体用法?C# Document.GetTextDocument怎么用?C# Document.GetTextDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.GetTextDocument方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RetrieveAllCodeItems
/// <summary>
/// Walks the given document and constructs a <see cref="SetCodeItems" /> of CodeItems
/// within it including regions.
/// </summary>
/// <param name="document">The document to walk.</param>
/// <returns>The set of code items within the document, including regions.</returns>
internal SetCodeItems RetrieveAllCodeItems(Document document)
{
var codeItems = new SetCodeItems();
var fileCodeModel = RetrieveFileCodeModel(document.ProjectItem);
RetrieveCodeItems(codeItems, fileCodeModel);
codeItems.AddRange(_codeModelHelper.RetrieveCodeRegions(document.GetTextDocument()));
return codeItems;
}
示例2: RetrieveAllCodeItems
/// <summary>
/// Walks the given document and constructs a <see cref="SetCodeItems" /> of CodeItems
/// within it including regions.
/// </summary>
/// <param name="document">The document to walk.</param>
/// <returns>The set of code items within the document, including regions.</returns>
internal SetCodeItems RetrieveAllCodeItems(Document document)
{
var codeItems = new SetCodeItems();
if (document.ProjectItem != null)
{
RetrieveCodeItems(codeItems, document.ProjectItem.FileCodeModel);
}
codeItems.AddRange(_codeModelHelper.RetrieveCodeRegions(document.GetTextDocument()));
return codeItems;
}
示例3: SelectCodeItem
/// <summary>
/// Attempts to select the text of the specified code item.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="codeItem">The code item.</param>
internal static void SelectCodeItem(Document document, BaseCodeItem codeItem)
{
var textDocument = document.GetTextDocument();
if (textDocument == null) return;
try
{
codeItem.RefreshCachedPositionAndName();
textDocument.Selection.MoveToPoint(codeItem.StartPoint, false);
textDocument.Selection.MoveToPoint(codeItem.EndPoint, true);
textDocument.Selection.SwapAnchor();
}
catch (Exception)
{
// Select operation may fail if element is no longer available.
}
finally
{
// Always set focus within the code editor window.
document.Activate();
}
}
示例4: MoveToCodeItem
/// <summary>
/// Attempts to move the cursor to the specified code item.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="codeItem">The code item.</param>
/// <param name="centerOnWhole">True if the whole element should be used for centering.</param>
internal static void MoveToCodeItem(Document document, BaseCodeItem codeItem, bool centerOnWhole)
{
var textDocument = document.GetTextDocument();
if (textDocument == null) return;
try
{
object viewRangeEnd = null;
TextPoint navigatePoint = null;
codeItem.RefreshCachedPositionAndName();
textDocument.Selection.MoveToPoint(codeItem.StartPoint, false);
if (centerOnWhole)
{
viewRangeEnd = codeItem.EndPoint;
}
var codeItemElement = codeItem as BaseCodeItemElement;
if (codeItemElement != null)
{
navigatePoint = codeItemElement.CodeElement.GetStartPoint(vsCMPart.vsCMPartNavigate);
}
textDocument.Selection.AnchorPoint.TryToShow(vsPaneShowHow.vsPaneShowCentered, viewRangeEnd);
if (navigatePoint != null)
{
textDocument.Selection.MoveToPoint(navigatePoint, false);
}
else
{
textDocument.Selection.FindText(codeItem.Name, (int)vsFindOptions.vsFindOptionsMatchInHiddenText);
textDocument.Selection.MoveToPoint(textDocument.Selection.AnchorPoint, false);
}
}
catch (Exception)
{
// Move operation may fail if element is no longer available.
}
finally
{
// Always set focus within the code editor window.
document.Activate();
}
}
示例5: GetTextDocument
/// <summary>
/// Gets the text document for the specified document.
/// </summary>
/// <param name="document">The document to act upon.</param>
/// <returns>The text document associated to the document.</returns>
public static TextDocument GetTextDocument(Document document)
{
var textDocument = document.GetTextDocument();
Assert.IsNotNull(textDocument);
return textDocument;
}
示例6: HasPreprocessorConditionalCompilationDirectives
/// <summary>
/// Determines if the specified document contains preprocessor conditional compilation directives.
/// </summary>
/// <param name="document">The document.</param>
/// <returns>True if preprocessor conditional compilation directives are detected, otherwise false.</returns>
private bool HasPreprocessorConditionalCompilationDirectives(Document document)
{
var textDocument = document.GetTextDocument();
if (textDocument != null)
{
var pattern = _package.UsePOSIXRegEx
? @"^\#(if|else|elif|endif)"
: @"^#(if|else|elif|endif)";
var editPoint = TextDocumentHelper.FirstOrDefaultMatch(textDocument, pattern);
if (editPoint != null)
{
return true;
}
}
return false;
}
示例7: RunCodeCleanupMarkup
/// <summary>
/// Attempts to run code cleanup on the specified markup document.
/// </summary>
/// <param name="document">The document for cleanup.</param>
/// <param name="isAutoSave">A flag indicating if occurring due to auto-save.</param>
private void RunCodeCleanupMarkup(Document document, bool isAutoSave)
{
var textDocument = document.GetTextDocument();
RunExternalFormatting(textDocument);
// Perform removal cleanup.
_removeWhitespaceLogic.RemoveEOLWhitespace(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAtTop(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAtBottom(textDocument);
_removeWhitespaceLogic.RemoveEOFTrailingNewLine(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesBeforeClosingTag(textDocument);
_removeWhitespaceLogic.RemoveBlankSpacesBeforeClosingAngleBracket(textDocument);
_removeWhitespaceLogic.RemoveMultipleConsecutiveBlankLines(textDocument);
// Perform insertion cleanup.
_insertWhitespaceLogic.InsertBlankSpaceBeforeSelfClosingAngleBracket(textDocument);
}
示例8: RunCodeCleanupGeneric
/// <summary>
/// Attempts to run code cleanup on the specified generic document.
/// </summary>
/// <param name="document">The document for cleanup.</param>
/// <param name="isAutoSave">A flag indicating if occurring due to auto-save.</param>
private void RunCodeCleanupGeneric(Document document, bool isAutoSave)
{
var textDocument = document.GetTextDocument();
RunExternalFormatting(textDocument);
// Perform removal cleanup.
_removeWhitespaceLogic.RemoveEOLWhitespace(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAtTop(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAtBottom(textDocument);
_removeWhitespaceLogic.RemoveEOFTrailingNewLine(textDocument);
_removeWhitespaceLogic.RemoveMultipleConsecutiveBlankLines(textDocument);
}
示例9: RunCodeCleanupCSharp
/// <summary>
/// Attempts to run code cleanup on the specified CSharp document.
/// </summary>
/// <param name="document">The document for cleanup.</param>
/// <param name="isAutoSave">A flag indicating if occurring due to auto-save.</param>
private void RunCodeCleanupCSharp(Document document, bool isAutoSave)
{
var textDocument = document.GetTextDocument();
bool isExternal = _codeCleanupAvailabilityLogic.IsDocumentExternal(document);
// Perform any actions that can modify the file code model first.
RunExternalFormatting(textDocument);
if (!isExternal)
{
_usingStatementCleanupLogic.RemoveUnusedUsingStatements(textDocument, isAutoSave);
_usingStatementCleanupLogic.SortUsingStatements(isAutoSave);
}
// Interpret the document into a collection of elements.
var codeItems = _codeModelManager.RetrieveAllCodeItems(document);
var regions = codeItems.OfType<CodeItemRegion>().ToList();
var usingStatements = codeItems.OfType<CodeItemUsingStatement>().ToList();
var namespaces = codeItems.OfType<CodeItemNamespace>().ToList();
var classes = codeItems.OfType<CodeItemClass>().ToList();
var delegates = codeItems.OfType<CodeItemDelegate>().ToList();
var enumerations = codeItems.OfType<CodeItemEnum>().ToList();
var events = codeItems.OfType<CodeItemEvent>().ToList();
var fields = codeItems.OfType<CodeItemField>().ToList();
var interfaces = codeItems.OfType<CodeItemInterface>().ToList();
var methods = codeItems.OfType<CodeItemMethod>().ToList();
var properties = codeItems.OfType<CodeItemProperty>().ToList();
var structs = codeItems.OfType<CodeItemStruct>().ToList();
// Build up more complicated collections.
var usingStatementBlocks = CodeModelHelper.GetCodeItemBlocks(usingStatements).ToList();
var usingStatementsThatStartBlocks = (from IEnumerable<CodeItemUsingStatement> block in usingStatementBlocks select block.First()).ToList();
var usingStatementsThatEndBlocks = (from IEnumerable<CodeItemUsingStatement> block in usingStatementBlocks select block.Last()).ToList();
var fieldsWithComments = fields.Where(x => x.StartPoint.Line < x.EndPoint.Line).ToList();
// Perform removal cleanup.
_removeRegionLogic.RemoveRegionsPerSettings(regions);
_removeWhitespaceLogic.RemoveEOLWhitespace(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAtTop(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAtBottom(textDocument);
_removeWhitespaceLogic.RemoveEOFTrailingNewLine(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAfterAttributes(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAfterOpeningBrace(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesBeforeClosingBrace(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesBetweenChainedStatements(textDocument);
_removeWhitespaceLogic.RemoveMultipleConsecutiveBlankLines(textDocument);
// Perform insertion of blank line padding cleanup.
_insertBlankLinePaddingLogic.InsertPaddingBeforeRegionTags(regions);
_insertBlankLinePaddingLogic.InsertPaddingAfterRegionTags(regions);
_insertBlankLinePaddingLogic.InsertPaddingBeforeEndRegionTags(regions);
_insertBlankLinePaddingLogic.InsertPaddingAfterEndRegionTags(regions);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements(usingStatementsThatStartBlocks);
_insertBlankLinePaddingLogic.InsertPaddingAfterCodeElements(usingStatementsThatEndBlocks);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements(namespaces);
_insertBlankLinePaddingLogic.InsertPaddingAfterCodeElements(namespaces);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements(classes);
_insertBlankLinePaddingLogic.InsertPaddingAfterCodeElements(classes);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements(delegates);
_insertBlankLinePaddingLogic.InsertPaddingAfterCodeElements(delegates);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements(enumerations);
_insertBlankLinePaddingLogic.InsertPaddingAfterCodeElements(enumerations);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements(events);
_insertBlankLinePaddingLogic.InsertPaddingAfterCodeElements(events);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements(fieldsWithComments);
_insertBlankLinePaddingLogic.InsertPaddingAfterCodeElements(fieldsWithComments);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements(interfaces);
_insertBlankLinePaddingLogic.InsertPaddingAfterCodeElements(interfaces);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements(methods);
_insertBlankLinePaddingLogic.InsertPaddingAfterCodeElements(methods);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements(properties);
_insertBlankLinePaddingLogic.InsertPaddingBetweenMultiLinePropertyAccessors(properties);
_insertBlankLinePaddingLogic.InsertPaddingAfterCodeElements(properties);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements(structs);
_insertBlankLinePaddingLogic.InsertPaddingAfterCodeElements(structs);
_insertBlankLinePaddingLogic.InsertPaddingBeforeCaseStatements(textDocument);
_insertBlankLinePaddingLogic.InsertPaddingBeforeSingleLineComments(textDocument);
// Perform insertion of explicit access modifier cleanup.
_insertExplicitAccessModifierLogic.InsertExplicitAccessModifiersOnClasses(classes);
_insertExplicitAccessModifierLogic.InsertExplicitAccessModifiersOnDelegates(delegates);
_insertExplicitAccessModifierLogic.InsertExplicitAccessModifiersOnEnumerations(enumerations);
//.........这里部分代码省略.........
示例10: HasAutoGeneratedHeader
/// <summary>
/// Determines if the specified document contains a header indicating it is auto-generated.
/// </summary>
/// <param name="document">The document.</param>
/// <returns>True an auto-generated header is detected, otherwise false.</returns>
private bool HasAutoGeneratedHeader(Document document)
{
var textDocument = document.GetTextDocument();
if (textDocument != null)
{
const string pattern = @"<auto-generated";
var editPoint = TextDocumentHelper.FirstOrDefaultMatch(textDocument, pattern);
if (editPoint != null)
{
return true;
}
}
return false;
}
示例11: RunRemoveUnusedUsingStatements
private static void RunRemoveUnusedUsingStatements(Document document)
{
_usingStatementCleanupLogic.RemoveUnusedUsingStatements(document.GetTextDocument(), false);
}
示例12: RunCodeCleanupGeneric
/// <summary>
/// Attempts to run code cleanup on the specified generic document.
/// </summary>
/// <param name="document">The document for cleanup.</param>
private void RunCodeCleanupGeneric(Document document)
{
var textDocument = document.GetTextDocument();
RunExternalFormatting(textDocument);
// Perform file header cleanup.
_fileHeaderLogic.UpdateFileHeader(textDocument);
// Perform removal cleanup.
_removeWhitespaceLogic.RemoveEOLWhitespace(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAtTop(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAtBottom(textDocument);
_removeWhitespaceLogic.RemoveEOFTrailingNewLine(textDocument);
_removeWhitespaceLogic.RemoveMultipleConsecutiveBlankLines(textDocument);
// Perform insertion cleanup.
_insertWhitespaceLogic.InsertEOFTrailingNewLine(textDocument);
}
示例13: RunCodeCleanupC
/// <summary>
/// Attempts to run code cleanup on the specified C/C++ document.
/// </summary>
/// <param name="document">The document for cleanup.</param>
private void RunCodeCleanupC(Document document)
{
var textDocument = document.GetTextDocument();
RunExternalFormatting(textDocument);
// Perform file header cleanup.
_fileHeaderLogic.UpdateFileHeader(textDocument);
// Perform removal cleanup.
_removeWhitespaceLogic.RemoveEOLWhitespace(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAtTop(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAtBottom(textDocument);
_removeWhitespaceLogic.RemoveEOFTrailingNewLine(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesAfterOpeningBrace(textDocument);
_removeWhitespaceLogic.RemoveBlankLinesBeforeClosingBrace(textDocument);
_removeWhitespaceLogic.RemoveMultipleConsecutiveBlankLines(textDocument);
// Perform insertion of blank line padding cleanup.
_insertBlankLinePaddingLogic.InsertPaddingBeforeSingleLineComments(textDocument);
// Perform insertion of whitespace cleanup.
_insertWhitespaceLogic.InsertEOFTrailingNewLine(textDocument);
}
示例14: HasPreprocessorConditionalCompilationDirectives
/// <summary>
/// Determines if the specified document contains preprocessor conditional compilation directives.
/// </summary>
/// <param name="document">The document.</param>
/// <returns>True if preprocessor conditional compilation directives are detected, otherwise false.</returns>
private bool HasPreprocessorConditionalCompilationDirectives(Document document)
{
var textDocument = document.GetTextDocument();
if (textDocument != null)
{
const string pattern = @"^[ \t]*#(if|else|elif|endif|pragma)";
var editPoint = TextDocumentHelper.FirstOrDefaultMatch(textDocument, pattern);
if (editPoint != null)
{
return true;
}
}
return false;
}