本文整理汇总了C#中IVsTextLines.UnlockBufferEx方法的典型用法代码示例。如果您正苦于以下问题:C# IVsTextLines.UnlockBufferEx方法的具体用法?C# IVsTextLines.UnlockBufferEx怎么用?C# IVsTextLines.UnlockBufferEx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsTextLines
的用法示例。
在下文中一共展示了IVsTextLines.UnlockBufferEx方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SearchForCodeBlocks
//.........这里部分代码省略.........
string commentText;
// Read all the token looking for the code blocks inside a Snippet Statements
// nested in an External Source statement. Note that the standard IronPython
// parser does not return such statements and this is the reason for this
// parser.
while (!tokenizer.IsEndOfFile) {
token = tokenizer.Next();
// This parser is strange in that it is only interested in comments:
// an external code statement is in the form
// #ExternalSource("PathOfTheOriginalFile", originalLineNumber)
// ... (some code) ...
// #End ExternalSource
// and a snippet statement is
// # Snippet Statement
// ... (some code) ...
// #End Snippet Statement
// So if we want to find the text region inside a snippet nested
// inside an external source, we are only interested in the comment tokens.
if (TokenKind.Comment != token.Kind) {
continue;
}
// The comments are line comments, so the comment's text is everything that
// is after the beginning of the comment.
commentText = CleanCommentStart(lineText.Substring(tokenizer.StartLocation.Column));
if (string.IsNullOrEmpty(commentText)) {
continue;
}
switch (state) {
case SimpleParserState.WaitForExternalSource:
// This function returns a non zero value only if the comment text
// is a valid external source statment.
blockSpan.ulHTMLCookie = ParseExternalSource(commentText);
if (0 != blockSpan.ulHTMLCookie) {
// The CodeDOM provider is adding 1 to the line number, but in this
// case the number is actualy the HTML editor's cookie, so we have to
// restore the original value.
blockSpan.ulHTMLCookie -= 1;
state = SimpleParserState.WaitForSnippet;
}
break;
case SimpleParserState.WaitForSnippet:
// Check if this comment is the beginning of a snippet block.
if (IsBeginSnippet(commentText)) {
// This is the beginning of a snippet block, so
// the actual code will start at the beginning of the
// next line.
blockSpan.CodeSpan.iStartLine = line + 1;
// Set the default for the start index.
blockSpan.CodeSpan.iStartIndex = 0;
// Now we have to find the end of the snippet section
// to complete the span of the code.
state = SimpleParserState.WaitForEndSnippet;
} else if (IsEndExternalSource(commentText)) {
// This was and external block not related to the HTML editor.
// Reset the text span and wait for the next external source.
blockSpan = new TextSpanAndCookie();
state = SimpleParserState.WaitForExternalSource;
}
break;
case SimpleParserState.WaitForEndSnippet:
if (IsEndSnippet(commentText)) {
// The code block ends at the end of the line before
// this token.
// Update the data about the code span and add the
// block to the list of the blocks found.
blockSpan.CodeSpan.iEndLine = line - 1;
ErrorHandler.ThrowOnFailure(
buffer.GetLengthOfLine(line - 1, out blockSpan.CodeSpan.iEndIndex));
blocks.Add(blockSpan);
blockSpan = new TextSpanAndCookie();
state = SimpleParserState.WaitForEndExternal;
}
break;
case SimpleParserState.WaitForEndExternal:
// We expect only one snippet block inside the external source
// section, so here we skip everything between the end of the first
// snippet block and the end of the external code section.
if (IsEndExternalSource(commentText)) {
state = SimpleParserState.WaitForExternalSource;
}
break;
}
}
}
}
} finally {
// Make sure that the buffer is always unlocked when we exit this function.
buffer.UnlockBufferEx((uint)BufferLockFlags.BLF_READ);
}
}
示例2: SearchForCodeBlocks
// »щет в исходном файле все блоки, обрамленные прагмой #line N / #line default
private void SearchForCodeBlocks(IVsTextLines buffer)
{
ErrorHandler.ThrowOnFailure(buffer.LockBufferEx((uint)BufferLockFlags.BLF_READ));
try
{
int totalLines;
ErrorHandler.ThrowOnFailure(buffer.GetLineCount(out totalLines));
var state = ParseState.WaitForBlockStart;
var blockSpan = new TextSpanAndCookie();
for (int line = 0; line < totalLines; ++line)
{
int lineLen;
ErrorHandler.ThrowOnFailure(buffer.GetLengthOfLine(line, out lineLen));
string lineText;
ErrorHandler.ThrowOnFailure(buffer.GetLineText(line, 0, line, lineLen, out lineText));
if (state == ParseState.WaitForBlockStart)
{
var match = _linePragmaRegex.Match(lineText);
if (match.Success)
{
blockSpan.ulHTMLCookie = uint.Parse(match.Groups[1].Value, NumberStyles.Integer, CultureInfo.InvariantCulture);
blockSpan.CodeSpan = new TextSpan();
blockSpan.CodeSpan.iStartLine = line + 1;
blockSpan.CodeSpan.iStartIndex = 0;
state = ParseState.WaitForBlockEnd;
}
}
else
{
if (lineText.Trim().StartsWith("#line default", StringComparison.InvariantCultureIgnoreCase))
{
blockSpan.CodeSpan.iEndLine = line - 1;
buffer.GetLengthOfLine(blockSpan.CodeSpan.iEndLine, out blockSpan.CodeSpan.iEndIndex);
blocks.Add(blockSpan);
blockSpan = new TextSpanAndCookie();
state = ParseState.WaitForBlockStart;
}
}
}
}
finally
{
// Make sure that the buffer is always unlocked when we exit this function.
buffer.UnlockBufferEx((uint)BufferLockFlags.BLF_READ);
}
}