本文整理汇总了C#中IDocument.GetLineByNumber方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.GetLineByNumber方法的具体用法?C# IDocument.GetLineByNumber怎么用?C# IDocument.GetLineByNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.GetLineByNumber方法的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.GetLineByNumber(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.GetLineByNumber(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.GetLineByNumber(startLine + lines.Count);
document.Remove(line.Offset, line.TotalLength);
}
}
}
示例2: 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.GetLineByNumber(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.GetLineByNumber(lineNumber - 1);
}
return document.GetText(line.Offset + line.Length, line.DelimiterLength);
}
示例3: ConvertTextDocumentToBlock
/// <summary>
/// Converts a readonly TextDocument to a Block and applies the provided highlighter.
/// </summary>
public static Block ConvertTextDocumentToBlock(IDocument document, IHighlighter highlighter)
{
if (document == null)
throw new ArgumentNullException("document");
// Table table = new Table();
// table.Columns.Add(new TableColumn { Width = GridLength.Auto });
// table.Columns.Add(new TableColumn { Width = new GridLength(1, GridUnitType.Star) });
// TableRowGroup trg = new TableRowGroup();
// table.RowGroups.Add(trg);
Paragraph p = new Paragraph();
p.TextAlignment = TextAlignment.Left;
for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++) {
if (lineNumber > 1)
p.Inlines.Add(new LineBreak());
var line = document.GetLineByNumber(lineNumber);
// TableRow row = new TableRow();
// trg.Rows.Add(row);
// row.Cells.Add(new TableCell(new Paragraph(new Run(lineNumber.ToString()))) { TextAlignment = TextAlignment.Right });
// Paragraph p = new Paragraph();
// row.Cells.Add(new TableCell(p));
if (highlighter != null) {
HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
p.Inlines.AddRange(highlightedLine.ToRichText().CreateRuns());
} else {
p.Inlines.Add(document.GetText(line));
}
}
return p;
}
示例4: EntityBookmark
public EntityBookmark(IUnresolvedEntity entity, IDocument document)
{
this.entity = entity;
int lineNr = entity.Region.BeginLine;
if (document != null && lineNr > 0 && lineNr < document.LineCount) {
this.line = document.GetLineByNumber(lineNr);
}
}
示例5: AddMark
public void AddMark(SDBookmark bookmark, IDocument document, int line)
{
int lineStartOffset = document.GetLineByNumber(line).Offset;
int column = 1 + DocumentUtilities.GetWhitespaceAfter(document, lineStartOffset).Length;
bookmark.Location = new TextLocation(line, column);
bookmark.FileName = FileName.Create(document.FileName);
AddMark(bookmark);
}
示例6: AttachTo
internal void AttachTo(IDocument document)
{
if (isDeleted)
return;
Debug.Assert(currentDocument == null && document != null);
this.currentDocument = document;
line = Math.Min(line, document.LineCount);
column = Math.Min(column, document.GetLineByNumber(line).Length + 1);
baseAnchor = document.CreateAnchor(document.GetOffset(line, column));
baseAnchor.MovementType = movementType;
baseAnchor.SurviveDeletion = surviveDeletion;
baseAnchor.Deleted += baseAnchor_Deleted;
}
示例7: DocumentSequence
public DocumentSequence(IDocument document, Dictionary<string, int> hashDict)
{
this.hashes = new int[document.LineCount];
// 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.LineCount; i++) {
string text = document.GetText(document.GetLineByNumber(i));
int hash;
if (!hashDict.TryGetValue(text, out hash)) {
hash = hashDict.Count;
hashDict.Add(text, hash);
}
hashes[i - 1] = hash;
}
}
示例8:
public static QuickFix ForFirstLineInRegion
(DomRegion region, IDocument document) {
// Note that we could display an arbitrary amount of
// context to the user: ranging from one line to tens,
// hundreds..
var text = document.GetText
( offset: document.GetOffset(region.BeginLine, column: 0)
, length: document.GetLineByNumber
(region.BeginLine).Length)
.Trim();
return new QuickFix
{ FileName = region.FileName
, Line = region.BeginLine
, Column = region.BeginColumn
, Text = text};
}
示例9: 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.GetLineByNumber(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);
}
示例10: ConvertTextDocumentToRichText
/// <summary>
/// Converts an IDocument to a RichText and applies the provided highlighter.
/// </summary>
public static RichText ConvertTextDocumentToRichText(IDocument document, IHighlighter highlighter)
{
if (document == null)
throw new ArgumentNullException("document");
var texts = new List<RichText>();
for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++) {
var line = document.GetLineByNumber(lineNumber);
if (lineNumber > 1)
texts.Add(line.PreviousLine.DelimiterLength == 2 ? "\r\n" : "\n");
if (highlighter != null) {
HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
texts.Add(highlightedLine.ToRichText());
} else {
texts.Add(document.GetText(line));
}
}
return RichText.Concat(texts.ToArray());
}
示例11: ConvertTextDocumentToBlock
/// <summary>
/// Converts an IDocument to a Block and applies the provided highlighter.
/// </summary>
public static Block ConvertTextDocumentToBlock(IDocument document, IHighlighter highlighter)
{
if (document == null)
throw new ArgumentNullException("document");
Paragraph p = new Paragraph();
p.TextAlignment = TextAlignment.Left;
for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++) {
if (lineNumber > 1)
p.Inlines.Add(new LineBreak());
var line = document.GetLineByNumber(lineNumber);
if (highlighter != null) {
HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
p.Inlines.AddRange(highlightedLine.ToRichText().CreateRuns());
} else {
p.Inlines.Add(document.GetText(line));
}
}
return p;
}
示例12: GetNewLineFromDocument
/// <summary>
/// Gets the newline sequence used in the document at the specified line.
/// </summary>
public static string GetNewLineFromDocument(IDocument document, int lineNumber)
{
IDocumentLine line = document.GetLineByNumber(lineNumber);
if (line.DelimiterLength == 0) {
// at the end of the document, there's no line delimiter, so use the delimiter
// from the previous line
line = line.PreviousLine;
if (line == null)
return Environment.NewLine;
}
return document.GetText(line.Offset + line.Length, line.DelimiterLength);
}
示例13: GetStartOffset
static int GetStartOffset(IDocument document, DomRegion bodyRegion)
{
if (bodyRegion.BeginLine < 1)
return 0;
if (bodyRegion.BeginLine > document.LineCount)
return document.TextLength;
var line = document.GetLineByNumber(bodyRegion.BeginLine);
int lineStart = line.Offset;
int bodyStartOffset = lineStart + bodyRegion.BeginColumn - 1;
for (int i = lineStart; i < bodyStartOffset; i++) {
if (!char.IsWhiteSpace(document.GetCharAt(i))) {
// Non-whitespace in front of body start:
// Use the body start as start offset
return bodyStartOffset;
}
}
// Only whitespace in front of body start:
// Use the end of the previous line as start offset
return line.PreviousLine != null ? line.PreviousLine.EndOffset : bodyStartOffset;
}
示例14: NeedEndregion
bool NeedEndregion(IDocument document)
{
int regions = 0;
int endregions = 0;
for (int i = 1; i <= document.LineCount; i++) {
string text = document.GetText(document.GetLineByNumber(i)).Trim();
if (text.StartsWith("#region", StringComparison.Ordinal)) {
++regions;
} else if (text.StartsWith("#endregion", StringComparison.Ordinal)) {
++endregions;
}
}
return regions > endregions;
}
示例15: ConvertRegionToSingleLineSegment
static WixDocumentLineSegment ConvertRegionToSingleLineSegment(IDocument document, DomRegion region)
{
IDocumentLine documentLine = document.GetLineByNumber(region.BeginLine);
return new WixDocumentLineSegment(documentLine.Offset + region.BeginColumn - 1,
region.EndColumn - region.BeginColumn + 1);
}