當前位置: 首頁>>代碼示例>>C#>>正文


C# Text.SourceText類代碼示例

本文整理匯總了C#中Microsoft.CodeAnalysis.Text.SourceText的典型用法代碼示例。如果您正苦於以下問題:C# SourceText類的具體用法?C# SourceText怎麽用?C# SourceText使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SourceText類屬於Microsoft.CodeAnalysis.Text命名空間,在下文中一共展示了SourceText類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的Microsoft.CodeAnalysis.Text.SourceText類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。