开发者

Current Line For Visual Studio Macros

开发者 https://www.devze.com 2022-12-25 13:21 出处:网络
How can I read开发者_如何学Go text of a current line (where cursor is situated) from Macros? I\'m going to use such a function:

How can I read开发者_如何学Go text of a current line (where cursor is situated) from Macros?

I'm going to use such a function:

 Public Sub AddTextToChangeLogFile()
    Dim textOnACurrentLine As ???
    textOnACurrentLine = ???

    If textOnACurrentLine.Text <> String.Empty Then
        Dim sw As New StreamWriter("C:\###\Changes.txt", True)
        sw.WriteLine(textOnACurrentLine + ". file: " + DTE.ActiveDocument.Name)
        sw.Close()
    End If
End Sub


You can use something like:

Dim textOnACurrentLine As String
DTE.ActiveDocument.Selection.StartOfLine(0)
DTE.ActiveDocument.Selection.EndOfLine(True)
textOnACurrentLine = DTE.ActiveDocument.Selection.Text


Get the line index from the Selection and use an EditPoint, like this:

TextSelection text_selection = (TextSelection)m_DTE.ActiveDocument.Selection;
int line_index = text_selection.ActivePoint.Line;
TextDocument text_doc = (TextDocument)m_DTE.ActiveDocument.Object("");
EditPoint edit_point = text_doc.CreateEditPoint();
string line = edit_point.GetLines(line_index, line_index+1);
0

精彩评论

暂无评论...
验证码 换一张
取 消