本文整理汇总了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);
}
示例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);
}
}
}
示例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);
}