当前位置: 首页>>代码示例>>C#>>正文


C# IDocument.GetLineByNumber方法代码示例

本文整理汇总了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);
				}
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:27,代码来源:SortSelectionCommand.cs

示例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);
 }
开发者ID:hazama-yuinyan,项目名称:BVEEditor,代码行数:15,代码来源:DocumentUtilities.cs

示例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;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:32,代码来源:DocumentPrinter.cs

示例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);
			}
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:8,代码来源:EntityBookmark.cs

示例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);
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:8,代码来源:BookmarkManager.cs

示例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;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:13,代码来源:PermanentAnchor.cs

示例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;
			}
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:16,代码来源:DocumentSequence.cs

示例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};
        }
开发者ID:sphynx79,项目名称:dotfiles,代码行数:17,代码来源:QuickFix.cs

示例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);
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:17,代码来源:WixDocumentLineSegment.cs

示例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());
		}
开发者ID:ratoy,项目名称:SharpDevelop,代码行数:21,代码来源:DocumentPrinter.cs

示例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;
		}
开发者ID:ratoy,项目名称:SharpDevelop,代码行数:22,代码来源:DocumentPrinter.cs

示例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);
		}
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:15,代码来源:NewLineFinder.cs

示例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;
 }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:20,代码来源:ParseInformation.cs

示例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;
		}
开发者ID:krunalc,项目名称:SharpDevelop,代码行数:14,代码来源:CSharpFormattingStrategy.cs

示例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);
		}
开发者ID:hefnerliu,项目名称:SharpDevelop,代码行数:6,代码来源:WixDocumentLineSegment.cs


注:本文中的IDocument.GetLineByNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。