本文整理汇总了C#中IDocument.GetLine方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.GetLine方法的具体用法?C# IDocument.GetLine怎么用?C# IDocument.GetLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.GetLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SortLines
public void SortLines(IDocument document, int startLine, int endLine, StringComparer comparer, bool removeDuplicates)
{
List<string> lines = new List<string>();
for (int i = startLine; i <= endLine; ++i) {
IDocumentLine line = document.GetLine(i);
lines.Add(document.GetText(line.Offset, line.Length));
}
lines.Sort(comparer);
if (removeDuplicates) {
lines = lines.Distinct(comparer).ToList();
}
using (document.OpenUndoGroup()) {
for (int i = 0; i < lines.Count; ++i) {
IDocumentLine line = document.GetLine(startLine + i);
document.Replace(line.Offset, line.Length, lines[i]);
}
// remove removed duplicate lines
for (int i = startLine + lines.Count; i <= endLine; ++i) {
IDocumentLine line = document.GetLine(startLine + lines.Count);
document.Remove(line.Offset, line.TotalLength);
}
}
}
示例2: SetPosition
public static void SetPosition(FileName fileName, IDocument document, int markerStartLine, int markerStartColumn, int markerEndLine, int markerEndColumn)
{
if (document == null)
return;
Remove();
startLine = markerStartLine;
startColumn = markerStartColumn;
endLine = markerEndLine;
endColumn = markerEndColumn;
if (startLine < 1 || startLine > document.TotalNumberOfLines)
return;
if (endLine < 1 || endLine > document.TotalNumberOfLines) {
endLine = startLine;
endColumn = int.MaxValue;
}
if (startColumn < 1)
startColumn = 1;
IDocumentLine line = document.GetLine(startLine);
if (endColumn < 1 || endColumn > line.Length)
endColumn = line.Length;
instance = new CurrentLineBookmark(fileName, new Location(startColumn, startLine));
BookmarkManager.AddMark(instance);
}
示例3: InsertCodeAtEnd
/// <summary>
/// Ensure that code is inserted correctly in {} code blocks - SD2-1180
/// </summary>
public override void InsertCodeAtEnd(DomRegion region, IDocument document, params AbstractNode[] nodes)
{
string beginLineIndentation = GetIndentation(document, region.BeginLine);
int insertionLine = region.EndLine - 1;
IDocumentLine endLine = document.GetLine(region.EndLine);
string endLineText = endLine.Text;
int originalPos = region.EndColumn - 2; // -1 for column coordinate => offset, -1 because EndColumn is after the '}'
int pos = originalPos;
if (pos >= endLineText.Length || endLineText[pos] != '}') {
LoggingService.Warn("CSharpCodeGenerator.InsertCodeAtEnd: position is invalid (not pointing to '}')"
+ " endLineText=" + endLineText + ", pos=" + pos);
} else {
for (pos--; pos >= 0; pos--) {
if (!char.IsWhiteSpace(endLineText[pos])) {
// range before '}' is not empty: we cannot simply insert in the line before the '}', so
//
pos++; // set pos to first whitespace character / the '{' character
if (pos < originalPos) {
// remove whitespace between last non-white character and the '}'
document.Remove(endLine.Offset + pos, originalPos - pos);
}
// insert newline and same indentation as used in beginLine before the '}'
document.Insert(endLine.Offset + pos, Environment.NewLine + beginLineIndentation);
insertionLine++;
pos = region.BeginColumn - 1;
if (region.BeginLine == region.EndLine && pos >= 1 && pos < endLineText.Length) {
// The whole block was in on a single line, e.g. "get { return field; }".
// Insert an additional newline after the '{'.
originalPos = pos = endLineText.IndexOf('{', pos);
if (pos >= 0 && pos < region.EndColumn - 1) {
// find next non-whitespace after originalPos
originalPos++; // point to insertion position for newline after {
for (pos++; pos < endLineText.Length; pos++) {
if (!char.IsWhiteSpace(endLineText[pos])) {
// remove all between originalPos and pos
if (originalPos < pos) {
document.Remove(endLine.Offset + originalPos, pos - originalPos);
}
document.Insert(endLine.Offset + originalPos, Environment.NewLine + beginLineIndentation + '\t');
insertionLine++;
break;
}
}
}
}
break;
}
}
}
InsertCodeAfter(insertionLine, document, beginLineIndentation + this.Options.IndentString, nodes);
}
示例4: GetClassEndLine
IDocumentLine GetClassEndLine(IDocument doc)
{
int line = doc.TotalNumberOfLines;
while (line > 0) {
IDocumentLine documentLine = doc.GetLine(line);
if (documentLine.Text.Trim() == "end") {
return documentLine;
}
line--;
}
return doc.GetLine(doc.TotalNumberOfLines);
}
示例5: Resolve
/// <summary>
/// Attempts to resolve a reference to a resource.
/// </summary>
/// <param name="fileName">The name of the file that contains the expression to be resolved.</param>
/// <param name="document">The document that contains the expression to be resolved.</param>
/// <param name="caretLine">The 0-based line in the file that contains the expression to be resolved.</param>
/// <param name="caretColumn">The 0-based column position of the expression to be resolved.</param>
/// <param name="charTyped">The character that has been typed at the caret position but is not yet in the buffer (this is used when invoked from code completion), or <c>null</c>.</param>
/// <returns>A <see cref="ResourceResolveResult"/> that describes which resource is referenced by the expression at the specified position in the specified file, or <c>null</c> if that expression does not reference a (known) resource or if the specified position is invalid.</returns>
public ResourceResolveResult Resolve(string fileName, IDocument document, int caretLine, int caretColumn, char? charTyped)
{
if (fileName == null || document == null) {
LoggingService.Debug("ResourceToolkit: "+this.GetType().ToString()+".Resolve called with null fileName or document argument");
return null;
}
if (caretLine < 0 || caretColumn < 0 || caretLine >= document.TotalNumberOfLines || caretColumn >= document.GetLine(caretLine + 1).TotalLength) {
LoggingService.Debug("ResourceToolkit: "+this.GetType().ToString()+".Resolve called with invalid position arguments");
return null;
}
return this.Resolve(fileName, document, caretLine, caretColumn, document.PositionToOffset(caretLine + 1, caretColumn + 1), charTyped);
}
示例6: IsInHeader
static bool IsInHeader(IDocument doc, int max)
{
bool result = true;
for(int i = 1; i < max; ++i){
var line_str = doc.GetLine(i).Text;
if(pos_stmt_searcher.IsMatch(line_str)){
result = false;
break;
}
}
return result;
}
示例7: AttachTo
internal void AttachTo(IDocument document)
{
if (isDeleted)
return;
Debug.Assert(currentDocument == null && document != null);
this.currentDocument = document;
line = Math.Min(line, document.TotalNumberOfLines);
column = Math.Min(column, document.GetLine(line).Length + 1);
baseAnchor = document.CreateAnchor(document.PositionToOffset(line, column));
baseAnchor.MovementType = movementType;
baseAnchor.SurviveDeletion = surviveDeletion;
baseAnchor.Deleted += baseAnchor_Deleted;
}
示例8: IsValidSequencePoint
/// <summary>
/// Checks whether the sequence point can be added to the document.
/// </summary>
/// <remarks>
/// Checks for invalid start lines, start columns, end columns and end
/// lines that cannot fit in the document.</remarks>
bool IsValidSequencePoint(IDocument document, CodeCoverageSequencePoint sequencePoint)
{
if (sequencePoint.Line <= 0 || sequencePoint.EndLine <= 0 || sequencePoint.Column <= 0 || sequencePoint.EndColumn <= 0) {
return false;
} else if (sequencePoint.Line > document.TotalNumberOfLines) {
return false;
} else if (sequencePoint.EndLine > document.TotalNumberOfLines) {
return false;
} else if (sequencePoint.Line == sequencePoint.EndLine && sequencePoint.Column > sequencePoint.EndColumn) {
return false;
} else {
// Check the columns exist on the line.
IDocumentLine lineSegment = document.GetLine(sequencePoint.Line);
if (sequencePoint.Column > lineSegment.Length) {
return false;
}
IDocumentLine endLineSegment = document.GetLine(sequencePoint.EndLine);
if (sequencePoint.EndColumn > endLineSegment.Length + 1) {
return false;
}
}
return true;
}
示例9: DocumentSequence
public DocumentSequence(IDocument document, Dictionary<string, int> hashDict)
{
this.hashes = new int[document.TotalNumberOfLines];
// Construct a perfect hash for the document lines, and store the 'hash code'
// (really just a unique identifier for each line content) in our array.
for (int i = 1; i <= document.TotalNumberOfLines; i++) {
string text = document.GetLine(i).Text;
int hash;
if (!hashDict.TryGetValue(text, out hash)) {
hash = hashDict.Count;
hashDict.Add(text, hash);
}
hashes[i - 1] = hash;
}
}
示例10: InsertEventHandler
public override int InsertEventHandler(IDocument document, string eventHandler)
{
int line = document.TotalNumberOfLines;
IDocumentLine lastLineSegment = document.GetLine(line);
int offset = lastLineSegment.Offset + lastLineSegment.Length;
string newContent = "\r\n" + eventHandler;
if (lastLineSegment.Length > 0) {
// Add an extra new line between the last line and the event handler.
newContent = "\r\n" + newContent;
}
document.Insert(offset, newContent);
// Set position so it points to the line
// where the event handler was inserted.
return line + 1;
}
示例11: ConvertRegionToMultiLineSegment
static WixDocumentLineSegment ConvertRegionToMultiLineSegment(IDocument document, DomRegion region)
{
int length = 0;
int startOffset = 0;
for (int line = region.BeginLine; line <= region.EndLine; ++line) {
IDocumentLine currentDocumentLine = document.GetLine(line);
if (line == region.BeginLine) {
length += currentDocumentLine.TotalLength - region.BeginColumn;
startOffset = currentDocumentLine.Offset + region.BeginColumn - 1;
} else if (line < region.EndLine) {
length += currentDocumentLine.TotalLength;
} else {
length += region.EndColumn + 1;
}
}
return new WixDocumentLineSegment(startOffset, length);
}
示例12: ConvertRegionToSingleLineSegment
static WixDocumentLineSegment ConvertRegionToSingleLineSegment(IDocument document, DomRegion region)
{
IDocumentLine documentLine = document.GetLine(region.BeginLine);
return new WixDocumentLineSegment(documentLine.Offset + region.BeginColumn - 1,
region.EndColumn - region.BeginColumn + 1);
}
示例13: NeedEndregion
bool NeedEndregion(IDocument document)
{
int regions = 0;
int endregions = 0;
for (int i = 1; i <= document.TotalNumberOfLines; i++) {
string text = document.GetLine(i).Text.Trim();
if (text.StartsWith("#region")) {
++regions;
} else if (text.StartsWith("#endregion")) {
++endregions;
}
}
return regions > endregions;
}
示例14: FindFullExpression
public static ExpressionResult FindFullExpression(int caretLine, int caretColumn, IDocument document, string fileName)
{
IExpressionFinder expressionFinder = GetExpressionFinder(fileName);
if (expressionFinder == null)
return ExpressionResult.Empty;
if (caretColumn > document.GetLine(caretLine).Length)
return ExpressionResult.Empty;
return expressionFinder.FindFullExpression(document.Text, document.PositionToOffset(caretLine, caretColumn));
}
示例15: GetLineTerminator
/// <summary>
/// Gets the line terminator for the document around the specified line number.
/// </summary>
public static string GetLineTerminator(IDocument document, int lineNumber)
{
IDocumentLine line = document.GetLine(lineNumber);
if (line.DelimiterLength == 0) {
// at the end of the document, there's no line delimiter, so use the delimiter
// from the previous line
if (lineNumber == 1)
return Environment.NewLine;
line = document.GetLine(lineNumber - 1);
}
return document.GetText(line.Offset + line.Length, line.DelimiterLength);
}