• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Text.SourceText类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



SourceText类属于Microsoft.CodeAnalysis.Text命名空间,在下文中一共展示了SourceText类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ApiLine

 internal ApiLine(string text, TextSpan span, SourceText sourceText, string path)
 {
     this.Text = text;
     this.Span = span;
     this.SourceText = sourceText;
     this.Path = path;
 }
开发者ID:modulexcite,项目名称:PublicApiAnalyzer,代码行数:7,代码来源:DeclarePublicAPIAnalyzer.Impl.cs


示例2: SyntacticDocument

 protected SyntacticDocument(Document document, SourceText text, SyntaxTree tree, SyntaxNode root)
 {
     this.Document = document;
     this.Text = text;
     this.SyntaxTree = tree;
     this.Root = root;
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:7,代码来源:SyntacticDocument.cs


示例3: Collapse

        private TextChange Collapse(SourceText newText, List<TextChange> changes)
        {
            if (changes.Count == 0)
            {
                return new TextChange(new TextSpan(0, 0), "");
            }
            else if (changes.Count == 1)
            {
                return changes[0];
            }

            // The span we want to replace goes from the start of the first span to the end of
            // the  last span.
            var totalOldSpan = TextSpan.FromBounds(changes.First().Span.Start, changes.Last().Span.End);

            // We figure out the text we're replacing with by actually just figuring out the
            // new span in the newText and grabbing the text out of that.  The newSpan will
            // start from the same position as the oldSpan, but it's length will be the old
            // span's length + all the deltas we accumulate through each text change.  i.e.
            // if the first change adds 2 characters and the second change adds 4, then 
            // the newSpan will be 2+4=6 characters longer than the old span.
            var sumOfDeltas = changes.Sum(c => c.NewText.Length - c.Span.Length);
            var totalNewSpan = new TextSpan(totalOldSpan.Start, totalOldSpan.Length + sumOfDeltas);

            return new TextChange(totalOldSpan, newText.ToString(totalNewSpan));
        }
开发者ID:vslsnap,项目名称:roslyn,代码行数:26,代码来源:AbstractMemberInsertingCompletionProvider.cs


示例4: TestIsEmpty

 private static void TestIsEmpty(SourceText text)
 {
     Assert.Equal(0, text.Length);
     Assert.Same(string.Empty, text.ToString());
     Assert.Equal(1, text.Lines.Count);
     Assert.Equal(0, text.Lines[0].Span.Length);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:SourceTextTests.cs


示例5: GetWordSpan

        public static TextSpan GetWordSpan(SourceText text, int position,
            Func<char, bool> isWordStartCharacter, Func<char, bool> isWordCharacter)
        {
            int start = position;
            while (start > 0 && isWordStartCharacter(text[start - 1]))
            {
                start--;
            }

            // If we're brought up in the middle of a word, extend to the end of the word as well.
            // This means that if a user brings up the completion list at the start of the word they
            // will "insert" the text before what's already there (useful for qualifying existing
            // text).  However, if they bring up completion in the "middle" of a word, then they will
            // "overwrite" the text. Useful for correcting misspellings or just replacing unwanted
            // code with new code.
            int end = position;
            if (start != position)
            {
                while (end < text.Length && isWordCharacter(text[end]))
                {
                    end++;
                }
            }

            return TextSpan.FromBounds(start, end);
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:26,代码来源:CommonCompletionUtilities.cs


示例6: GetStartAndLengthOfLineBreakEndingAt

 /// <summary>
 /// Return startLineBreak = index-1, lengthLineBreak = 2   if there is a \r\n at index-1
 /// Return startLineBreak = index,   lengthLineBreak = 1   if there is a 1-char newline at index
 /// Return startLineBreak = index+1, lengthLineBreak = 0   if there is no newline at index.
 /// </summary>
 public static void GetStartAndLengthOfLineBreakEndingAt(SourceText text, int index, out int startLinebreak, out int lengthLinebreak)
 {
     char c = text[index];
     if (c == '\n')
     {
         if (index > 0 && text[index - 1] == '\r')
         {
             // "\r\n" is the only 2-character line break.
             startLinebreak = index - 1;
             lengthLinebreak = 2;
         }
         else
         {
             startLinebreak = index;
             lengthLinebreak = 1;
         }
     }
     else if (IsAnyLineBreakCharacter(c))
     {
         startLinebreak = index;
         lengthLinebreak = 1;
     }
     else
     {
         startLinebreak = index + 1;
         lengthLinebreak = 0;
     }
 }
开发者ID:riversky,项目名称:roslyn,代码行数:33,代码来源:TextUtilities.cs


示例7: 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


示例8: FillGaps

    private static IEnumerable<Range> FillGaps(SourceText text, IEnumerable<Range> ranges)
    {
        const string WhitespaceClassification = null;
        int current = 0;
        Range previous = null;

        foreach (Range range in ranges)
        {
            int start = range.TextSpan.Start;
            if (start > current)
            {
                yield return new Range(WhitespaceClassification, TextSpan.FromBounds(current, start), text);
            }

            if (previous == null || range.TextSpan != previous.TextSpan)
            {
                yield return range;
            }

            previous = range;
            current = range.TextSpan.End;
        }

        if (current < text.Length)
        {
            yield return new Range(WhitespaceClassification, TextSpan.FromBounds(current, text.Length), text);
        }
    }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:28,代码来源:Program.cs


示例9: ConvertClassifications

        private static List<SymbolDisplayPart> ConvertClassifications(
            SourceText sourceText, int startPosition, IEnumerable<ClassifiedSpan> classifiedSpans, bool insertSourceTextInGaps = false)
        {
            var parts = new List<SymbolDisplayPart>();
 
            foreach (var span in classifiedSpans)
            {
                // If there is space between this span and the last one, then add a space.
                if (startPosition != span.TextSpan.Start)
                {
                    if (insertSourceTextInGaps)
                    {
                        parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Text, null,
                            sourceText.ToString(TextSpan.FromBounds(
                                startPosition, span.TextSpan.Start))));
                    }
                    else
                    {
                        parts.AddRange(Space());
                    }
                }
 
                var kind = GetClassificationKind(span.ClassificationType);
                if (kind != null)
                {
                    parts.Add(new SymbolDisplayPart(kind.Value, null, sourceText.ToString(span.TextSpan)));

                    startPosition = span.TextSpan.End;
                }
            }
 
            return parts;
        }
开发者ID:tvsonar,项目名称:roslyn,代码行数:33,代码来源:Classifier.cs


示例10: PartitionChangesForDocument

        private IEnumerable<IEnumerable<TextChange>> PartitionChangesForDocument(IEnumerable<TextChange> changes, SourceText originalSourceText)
        {
            var partitionedChanges = new List<IEnumerable<TextChange>>();
            var currentPartition = new List<TextChange>();

            currentPartition.Add(changes.First());
            var currentPartitionEndLine = originalSourceText.Lines.GetLineFromPosition(changes.First().Span.End);

            foreach (var change in changes.Skip(1))
            {
                // If changes are on adjacent lines, consider them part of the same change.
                var changeStartLine = originalSourceText.Lines.GetLineFromPosition(change.Span.Start);
                if (changeStartLine.LineNumber >= currentPartitionEndLine.LineNumber + 2)
                {
                    partitionedChanges.Add(currentPartition);
                    currentPartition = new List<TextChange>();
                }

                currentPartition.Add(change);
                currentPartitionEndLine = originalSourceText.Lines.GetLineFromPosition(change.Span.End);
            }

            if (currentPartition.Any())
            {
                partitionedChanges.Add(currentPartition);
            }

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


示例11: UpdateText

        public void UpdateText(SourceText newText)
        {
            _updatding = true;
            _editor.Document.BeginUpdate();
            try
            {
                var changes = newText.GetTextChanges(_currentText);

                var offset = 0;

                foreach (var change in changes)
                {
                    _editor.Document.Replace(change.Span.Start + offset, change.Span.Length, new StringTextSource(change.NewText));

                    offset += change.NewText.Length - change.Span.Length;
                }

                _currentText = newText;
            }
            finally
            {
                _updatding = false;
                _editor.Document.EndUpdate();
            }
        }
开发者ID:mjheitland,项目名称:TableTweaker,代码行数:25,代码来源:AvalonEditTextContainer.cs


示例12: AvalonEditTextContainer

        public AvalonEditTextContainer(TextEditor editor)
        {
            _editor = editor;
            _currentText = SourceText.From(_editor.Text);

            _editor.Document.Changed += DocumentOnChanged;
        }
开发者ID:mjheitland,项目名称:TableTweaker,代码行数:7,代码来源:AvalonEditTextContainer.cs


示例13: AddAdditionalDocumentUndoUnit

 public AddAdditionalDocumentUndoUnit(
     VisualStudioWorkspaceImpl workspace,
     DocumentInfo docInfo,
     SourceText text)
     : base(workspace, docInfo, text)
 {
 }
开发者ID:TyOverby,项目名称:roslyn,代码行数:7,代码来源:VisualStudioWorkspaceImpl.AddAdditionalDocumentUndoUnit.cs


示例14: ConvertClassifications

        private static List<SymbolDisplayPart> ConvertClassifications(
            SourceText sourceText, IEnumerable<ClassifiedSpan> classifiedSpans)
        {
            var parts = new List<SymbolDisplayPart>();
 
            ClassifiedSpan? lastSpan = null;
            foreach (var span in classifiedSpans)
            {
                // If there is space between this span and the last one, then add a space.
                if (lastSpan != null && lastSpan.Value.TextSpan.End != span.TextSpan.Start)
                {
                    parts.AddRange(Space());
                }
 
                var kind = GetClassificationKind(span.ClassificationType);
                if (kind != null)
                {
                    parts.Add(new SymbolDisplayPart(kind.Value, null, sourceText.ToString(span.TextSpan)));
 
                    lastSpan = span;
                }
            }
 
            return parts;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:25,代码来源:Classifier.cs


示例15: Create

            public static StringSplitter Create(
                Document document, int position,
                SyntaxTree syntaxTree, SyntaxNode root, SourceText sourceText,
                bool useTabs, int tabSize, CancellationToken cancellationToken)
            {
                var token = root.FindToken(position);

                if (token.IsKind(SyntaxKind.StringLiteralToken))
                {
                    return new SimpleStringSplitter(
                        document, position, syntaxTree, root,
                        sourceText, token, useTabs, tabSize,
                        cancellationToken);
                }

                var interpolatedStringExpression = TryGetInterpolatedStringExpression(token, position);
                if (interpolatedStringExpression != null)
                {
                    return new InterpolatedStringSplitter(
                        document, position, syntaxTree, root,
                        sourceText, interpolatedStringExpression,
                        useTabs, tabSize, cancellationToken);
                }

                return null;
            }
开发者ID:RoryVL,项目名称:roslyn,代码行数:26,代码来源:SplitStringLiteralCommandHandler.StringSplitter.cs


示例16: IsTriggerAfterSpaceOrStartOfWordCharacter

 internal static bool IsTriggerAfterSpaceOrStartOfWordCharacter(SourceText text, int characterPosition, OptionSet options)
 {
     // Bring up on space or at the start of a word.
     var ch = text[characterPosition];
     return SpaceTypedNotBeforeWord(ch, text, characterPosition) ||
         (IsStartingNewWord(text, characterPosition) && options.GetOption(CompletionOptions.TriggerOnTypingLetters, LanguageNames.CSharp));
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:CompletionUtilities.cs


示例17: IsTriggerCharacter

        internal static bool IsTriggerCharacter(SourceText text, int characterPosition, OptionSet options)
        {
            var ch = text[characterPosition];
            if (ch == '.')
            {
                return true;
            }

            // Trigger for directive
            if (ch == '#')
            {
                return true;
            }

            // Trigger on pointer member access
            if (ch == '>' && characterPosition >= 1 && text[characterPosition - 1] == '-')
            {
                return true;
            }

            // Trigger on alias name
            if (ch == ':' && characterPosition >= 1 && text[characterPosition - 1] == ':')
            {
                return true;
            }

            if (options.GetOption(CompletionOptions.TriggerOnTypingLetters, LanguageNames.CSharp) && IsStartingNewWord(text, characterPosition))
            {
                return true;
            }

            return false;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:33,代码来源:CompletionUtilities.cs


示例18: GetChangeRanges

        public override IReadOnlyList<TextChangeRange> GetChangeRanges(SourceText oldText)
        {
            if (oldText == null)
            {
                throw new ArgumentNullException(nameof(oldText));
            }

            if (ReferenceEquals(_oldText, oldText))
            {
                // check whether the bases are same one
                return _changes;
            }

            if (_oldText.GetChangeRanges(oldText).Count == 0)
            {
                // okay, the bases are different, but the contents might be same.
                return _changes;
            }

            if (this == oldText)
            {
                return TextChangeRange.NoChanges;
            }

            return ImmutableArray.Create(new TextChangeRange(new TextSpan(0, oldText.Length), _newText.Length));
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:26,代码来源:ChangedText.cs


示例19: 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


示例20: CreateEngine

		internal static CacheIndentEngine CreateEngine(string text, out SourceText sourceText, OptionSet options = null)
		{
			if (options == null) {
				options = FormattingOptionsFactory.CreateMono ();
				//	options.AlignToFirstIndexerArgument = formatOptions.AlignToFirstMethodCallArgument = true;
			}

			var sb = new StringBuilder ();
			int offset = 0;
			for (int i = 0; i < text.Length; i++) {
				var ch = text [i];
				if (ch == '$') {
					offset = i;
					continue;
				}
				sb.Append (ch);
			}


			sourceText = SourceText.From (sb.ToString ());

			var result = new CacheIndentEngine (new CSharpIndentEngine (options));
			result.Update (sourceText, offset);
			return result;
		}
开发者ID:kdubau,项目名称:monodevelop,代码行数:25,代码来源:TextPasteIndentEngineTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Samples.ServerConnection类代码示例发布时间:2022-05-26
下一篇:
C# Utilities.DiagnosticDescription类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap