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


C# SourceText.GetSubText方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.Text.SourceText.GetSubText方法的典型用法代码示例。如果您正苦于以下问题:C# SourceText.GetSubText方法的具体用法?C# SourceText.GetSubText怎么用?C# SourceText.GetSubText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.Text.SourceText的用法示例。


在下文中一共展示了SourceText.GetSubText方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChangedText

        public ChangedText(SourceText oldText, IEnumerable<TextChange> changes)
        {
            if (oldText == null)
            {
                throw new ArgumentNullException("text");
            }

            if (changes == null)
            {
                throw new ArgumentNullException("changes");
            }

            var segments = ArrayBuilder<SourceText>.GetInstance();
            var changeRanges = ArrayBuilder<TextChangeRange>.GetInstance();
            int position = 0;

            foreach (var change in changes)
            {
                // there can be no overlapping changes
                if (change.Span.Start < position)
                {
                    throw new InvalidOperationException("The changes must be ordered and not overlapping.");
                }

                // if we've skipped a range, add
                if (change.Span.Start > position)
                {
                    var subText = oldText.GetSubText(new TextSpan(position, change.Span.Start - position));
                    CompositeText.AddSegments(segments, subText);
                }

                if (!string.IsNullOrEmpty(change.NewText))
                {
                    var segment = SourceText.From(change.NewText);
                    CompositeText.AddSegments(segments, segment);
                }

                position = change.Span.End;

                changeRanges.Add(new TextChangeRange(change.Span, change.NewText != null ? change.NewText.Length : 0));
            }

            if (position < oldText.Length)
            {
                var subText = oldText.GetSubText(new TextSpan(position, oldText.Length - position));
                CompositeText.AddSegments(segments, subText);
            }

            this.oldText = oldText;
            this.newText = new CompositeText(segments.ToImmutableAndFree());
            this.changes = changeRanges.ToImmutableAndFree();
        }
开发者ID:pheede,项目名称:roslyn,代码行数:52,代码来源:ChangedText.cs

示例2: GetCommentChangesForDocument

        private List<TextChange> GetCommentChangesForDocument(IEnumerable<IEnumerable<TextChange>> partitionedChanges, string projectName, SourceText oldDocumentText, SourceText newDocumentText)
        {
            var commentChanges = new List<TextChange>();

            foreach (var changePartition in partitionedChanges)
            {
                var startPosition = changePartition.First().Span.Start;
                var endPosition = changePartition.Last().Span.End;

                var startLineStartPosition = oldDocumentText.Lines.GetLineFromPosition(startPosition).Start;
                var endLineEndPosition = oldDocumentText.Lines.GetLineFromPosition(endPosition).End;

                var oldText = oldDocumentText.GetSubText(TextSpan.FromBounds(startLineStartPosition, endLineEndPosition));
                var adjustedChanges = changePartition.Select(c => new TextChange(TextSpan.FromBounds(c.Span.Start - startLineStartPosition, c.Span.End - startLineStartPosition), c.NewText));
                var newText = oldText.WithChanges(adjustedChanges);

                var warningText = GetConflictCommentText(
                    string.Format(WorkspacesResources.UnmergedChangeFromProject, projectName),
                    TrimBlankLines(oldText),
                    TrimBlankLines(newText));

                if (warningText != null)
                {
                    commentChanges.Add(new TextChange(TextSpan.FromBounds(startLineStartPosition, startLineStartPosition), warningText));
                }
            }

            return commentChanges;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:29,代码来源:AbstractLinkedFileMergeConflictCommentAdditionService.cs

示例3: Classify

        public async Task<IEnumerable<Range>> Classify(Document document, SourceText text)
        {
            var span = TextSpan.FromBounds(0, text.Length);

            IEnumerable<ClassifiedSpan> classifiedSpans = null;
            try
            {
                classifiedSpans = await Classifier.GetClassifiedSpansAsync(document, span);
            }
            catch (Exception ex)
            {
                Log.Exception(ex, "Exception during Classification of document: " + document.FilePath);
                return null;
            }

            var ranges = classifiedSpans.Select(classifiedSpan =>
                new Range
                {
                    ClassifiedSpan = classifiedSpan,
                    Text = text.GetSubText(classifiedSpan.TextSpan).ToString()
                });
            ranges = Merge(text, ranges);
            ranges = FilterByClassification(ranges);
            ranges = FillGaps(text, ranges);
            return ranges;
        }
开发者ID:KirillOsenkov,项目名称:SourceBrowser,代码行数:26,代码来源:Classifier.cs

示例4: GetTextChange

        private static TextChange GetTextChange(SourceText text, TextSpan sourceSpan)
        {
            var subText = text.GetSubText(sourceSpan).ToString();

            int i = 2;
            for (; i < subText.Length; i++)
            {
                if (!char.IsWhiteSpace(subText[i]))
                {
                    break;
                }
            }

            return new TextChange(new TextSpan(sourceSpan.Start + 2, i - 2), " ");
        }
开发者ID:Romanx,项目名称:StyleCopAnalyzers,代码行数:15,代码来源:SA1005CodeFixProvider.cs

示例5: Range

 public Range(string classification, TextSpan span, SourceText text)
     : this(classification, span, text.GetSubText(span).ToString())
 {
 }
开发者ID:ncrockhopper,项目名称:pcr,代码行数:4,代码来源:Range.cs

示例6: GetChangeList

        private ChangeList GetChangeList(IHierarchicalDifferenceCollection diff, DocumentId id, SourceText oldText, SourceText newText)
        {
            var spanChanges = new List<SpanChange>();
            foreach (var difference in diff)
            {
                var leftSpan = diff.LeftDecomposition.GetSpanInOriginal(difference.Left);
                var rightSpan = diff.RightDecomposition.GetSpanInOriginal(difference.Right);

                var leftText = oldText.GetSubText(leftSpan.ToTextSpan()).ToString();
                var rightText = newText.GetSubText(rightSpan.ToTextSpan()).ToString();

                var trackingSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(leftSpan, SpanTrackingMode.EdgeInclusive);

                var isDeletion = difference.DifferenceType == DifferenceType.Remove;
                var displayText = isDeletion ? GetDisplayText(leftText) : GetDisplayText(rightText);

                var spanChange = new SpanChange(trackingSpan, _buffer, id, displayText, leftText, rightText, isDeletion, this, engine);

                spanChanges.Add(spanChange);
            }

            return new ChangeList(spanChanges.ToArray());
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:23,代码来源:FileChange.cs

示例7: Update

		/// <inheritdoc />
		/// <remarks>
		///     If the <paramref name="position"/> is negative, the engine will
		///     update to: document.TextLength + (offset % document.TextLength+1)
		///     Otherwise it will update to: offset % document.TextLength+1
		/// </remarks>
		public void Update(SourceText sourceText, int position)
		{
			const int BUFFER_SIZE = 2000;
			
			if (currentEngine.Offset == position) {
				//positions match, nothing to be done
				return;
			} else if (currentEngine.Offset > position) {
				//moving backwards, so reset from previous saved location
				ResetEngineToPosition(sourceText, position);
			}

			// get the engine caught up
			int nextSave = (cachedEngines.Count == 0) ? BUFFER_SIZE : cachedEngines.Peek().Offset + BUFFER_SIZE;
			if (currentEngine.Offset + 1 == position) {
				char ch = sourceText[currentEngine.Offset];
				currentEngine.Push(ch);
				if (currentEngine.Offset == nextSave)
					cachedEngines.Push(currentEngine.Clone());
			} else {
				//bulk copy characters in case buffer is unmanaged 
				//(faster if we reduce managed/unmanaged transitions)
				while (currentEngine.Offset < position) {
					int endCut = currentEngine.Offset + BUFFER_SIZE;
					if (endCut > position)
						endCut = position;
					string buffer = sourceText.GetSubText(TextSpan.FromBounds(currentEngine.Offset, endCut)).ToString();
					foreach (char ch in buffer) {
						currentEngine.Push(ch);
						//ConsoleWrite ("pushing character '{0}'", ch);
						if (currentEngine.Offset == nextSave) {
							cachedEngines.Push(currentEngine.Clone());
							nextSave += BUFFER_SIZE;
						}
					}
				}
			}
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:44,代码来源:CacheIndentEngine.cs

示例8: TrimBlankLines

        private string TrimBlankLines(SourceText text)
        {
            int startLine, endLine;
            for (startLine = 0; startLine < text.Lines.Count; startLine++)
            {
                if (text.Lines[startLine].ToString().Any(c => !char.IsWhiteSpace(c)))
                {
                    break;
                }
            }

            for (endLine = text.Lines.Count - 1; endLine > startLine; endLine--)
            {
                if (text.Lines[endLine].ToString().Any(c => !char.IsWhiteSpace(c)))
                {
                    break;
                }
            }

            return startLine <= endLine
                ? text.GetSubText(TextSpan.FromBounds(text.Lines[startLine].Start, text.Lines[endLine].End)).ToString()
                : null;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:23,代码来源:AbstractLinkedFileMergeConflictCommentAdditionService.cs

示例9: CreateRange

 private Range CreateRange(SourceText text, TextSpan span, string classification)
 {
     return new Range(classification, span, text.GetSubText(span).ToString());
 }
开发者ID:KirillOsenkov,项目名称:SourceBrowser,代码行数:4,代码来源:Classifier.cs


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