本文整理汇总了C#中SourceLocation.GetLineSpan方法的典型用法代码示例。如果您正苦于以下问题:C# SourceLocation.GetLineSpan方法的具体用法?C# SourceLocation.GetLineSpan怎么用?C# SourceLocation.GetLineSpan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceLocation
的用法示例。
在下文中一共展示了SourceLocation.GetLineSpan方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGetSourceLocationInFile
public void TestGetSourceLocationInFile()
{
string sampleProgram = @"class X {
#line 20 ""d:\banana.cs""
int x;
}";
SyntaxTree syntaxTree = SyntaxFactory.ParseSyntaxTree(sampleProgram, "c:\\foo.cs");
TextSpan xSpan = new TextSpan(sampleProgram.IndexOf("x;"), 2);
TextSpan xToCloseBraceSpan = new TextSpan(xSpan.Start, sampleProgram.IndexOf("}") - xSpan.Start + 1);
Location locX = new SourceLocation(syntaxTree, xSpan);
Location locXToCloseBrace = new SourceLocation(syntaxTree, xToCloseBraceSpan);
FileLinePositionSpan flpsX = locX.GetLineSpan();
Assert.Equal("c:\\foo.cs", flpsX.Path);
Assert.Equal(2, flpsX.StartLinePosition.Line);
Assert.Equal(4, flpsX.StartLinePosition.Character);
Assert.Equal(2, flpsX.EndLinePosition.Line);
Assert.Equal(6, flpsX.EndLinePosition.Character);
flpsX = locX.GetMappedLineSpan();
Assert.Equal("d:\\banana.cs", flpsX.Path);
Assert.Equal(19, flpsX.StartLinePosition.Line);
Assert.Equal(4, flpsX.StartLinePosition.Character);
Assert.Equal(19, flpsX.EndLinePosition.Line);
Assert.Equal(6, flpsX.EndLinePosition.Character);
FileLinePositionSpan flpsXToCloseBrace = locXToCloseBrace.GetLineSpan();
Assert.Equal("c:\\foo.cs", flpsXToCloseBrace.Path);
Assert.Equal(2, flpsXToCloseBrace.StartLinePosition.Line);
Assert.Equal(4, flpsXToCloseBrace.StartLinePosition.Character);
Assert.Equal(3, flpsXToCloseBrace.EndLinePosition.Line);
Assert.Equal(1, flpsXToCloseBrace.EndLinePosition.Character);
flpsXToCloseBrace = locXToCloseBrace.GetMappedLineSpan();
Assert.Equal("d:\\banana.cs", flpsXToCloseBrace.Path);
Assert.Equal(19, flpsXToCloseBrace.StartLinePosition.Line);
Assert.Equal(4, flpsXToCloseBrace.StartLinePosition.Character);
Assert.Equal(20, flpsXToCloseBrace.EndLinePosition.Line);
Assert.Equal(1, flpsXToCloseBrace.EndLinePosition.Character);
}