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


C# SyntaxTree.GetLineSpan方法代码示例

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


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

示例1: UpdatePosition

        private DiagnosticData UpdatePosition(DiagnosticData diagnostic, SyntaxTree tree, int delta)
        {
            var start = Math.Min(Math.Max(diagnostic.TextSpan.Start + delta, 0), tree.Length);
            var newSpan = new TextSpan(start, start >= tree.Length ? 0 : diagnostic.TextSpan.Length);

            var mappedLineInfo = tree.GetMappedLineSpan(newSpan);
            var originalLineInfo = tree.GetLineSpan(newSpan);

            return new DiagnosticData(
                diagnostic.Id,
                diagnostic.Category,
                diagnostic.Message,
                diagnostic.ENUMessageForBingSearch,
                diagnostic.Severity,
                diagnostic.DefaultSeverity,
                diagnostic.IsEnabledByDefault,
                diagnostic.WarningLevel,
                diagnostic.CustomTags,
                diagnostic.Properties,
                diagnostic.Workspace,
                diagnostic.ProjectId,
                diagnostic.DocumentId,
                newSpan,
                mappedFilePath: mappedLineInfo.GetMappedFilePathIfExist(),
                mappedStartLine: mappedLineInfo.StartLinePosition.Line,
                mappedStartColumn: mappedLineInfo.StartLinePosition.Character,
                mappedEndLine: mappedLineInfo.EndLinePosition.Line,
                mappedEndColumn: mappedLineInfo.EndLinePosition.Character,
                originalFilePath: originalLineInfo.Path,
                originalStartLine: originalLineInfo.StartLinePosition.Line,
                originalStartColumn: originalLineInfo.StartLinePosition.Character,
                originalEndLine: originalLineInfo.EndLinePosition.Line,
                originalEndColumn: originalLineInfo.EndLinePosition.Character,
                description: diagnostic.Description,
                helpLink: diagnostic.HelpLink);
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:36,代码来源:DiagnosticIncrementalAnalyzer.cs

示例2: CheckBoundInitializers

        private static void CheckBoundInitializers(IEnumerable<ExpectedInitializer> expectedInitializers, SyntaxTree syntaxTree, ImmutableArray<BoundInitializer> boundInitializers, bool isStatic)
        {
            if (expectedInitializers == null)
            {
                Assert.Equal(0, boundInitializers.Length);
            }
            else
            {
                Assert.True(!boundInitializers.IsEmpty, "Expected non-null non-empty bound initializers");

                int numInitializers = expectedInitializers.Count();

                Assert.Equal(numInitializers, boundInitializers.Length);

                int i = 0;
                foreach (var expectedInitializer in expectedInitializers)
                {
                    var boundInit = boundInitializers[i++];
                    Assert.Equal(BoundKind.FieldInitializer, boundInit.Kind);

                    var boundFieldInit = (BoundFieldInitializer)boundInit;

                    var initValueSyntax = boundFieldInit.InitialValue.Syntax;
                    Assert.Same(initValueSyntax, boundInit.Syntax);
                    Assert.Equal(expectedInitializer.InitialValue, initValueSyntax.ToFullString());

                    var initValueLineNumber = syntaxTree.GetLineSpan(initValueSyntax.Span).StartLinePosition.Line;
                    Assert.Equal(expectedInitializer.LineNumber, initValueLineNumber);

                    Assert.Equal(expectedInitializer.FieldName, boundFieldInit.Field.Name);
                }
            }
        }
开发者ID:riversky,项目名称:roslyn,代码行数:33,代码来源:FieldInitializerBindingTests.cs

示例3: UpdateDiagnosticLocation

        private DiagnosticDataLocation UpdateDiagnosticLocation(
            DiagnosticDataLocation dataLocation, SyntaxTree tree, int delta)
        {
            var span = dataLocation.SourceSpan.Value;
            var start = Math.Min(Math.Max(span.Start + delta, 0), tree.Length);
            var newSpan = new TextSpan(start, start >= tree.Length ? 0 : span.Length);

            var mappedLineInfo = tree.GetMappedLineSpan(newSpan);
            var originalLineInfo = tree.GetLineSpan(newSpan);

            return new DiagnosticDataLocation(dataLocation.DocumentId, newSpan,
                originalFilePath: originalLineInfo.Path,
                originalStartLine: originalLineInfo.StartLinePosition.Line,
                originalStartColumn: originalLineInfo.StartLinePosition.Character,
                originalEndLine: originalLineInfo.EndLinePosition.Line,
                originalEndColumn: originalLineInfo.EndLinePosition.Character,
                mappedFilePath: mappedLineInfo.GetMappedFilePathIfExist(),
                mappedStartLine: mappedLineInfo.StartLinePosition.Line,
                mappedStartColumn: mappedLineInfo.StartLinePosition.Character,
                mappedEndLine: mappedLineInfo.EndLinePosition.Line,
                mappedEndColumn: mappedLineInfo.EndLinePosition.Character);
        }
开发者ID:Eyas,项目名称:roslyn,代码行数:22,代码来源:DiagnosticIncrementalAnalyzer.cs


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