我正在为单元测试目的在内存中创建一个工作区,但我无法访问某个 InvocationExpression 的符号信息(这是我正在测试的 CodeIssue 所必需的)。这是一个失败的测试的简化示例。请帮忙?
var solution =
Solution.Create(SolutionId.CreateNewId())
.AddCSharpProject(Title, Title, out projectId)
.AddMetadataReference(projectId, MetadataReference.CreateAssemblyReference("mscorlib"))
.AddMetadataReference(projectId, MetadataReference.CreateAssemblyReference("Microsoft.CSharp"))
.AddMetadataReference(projectId, MetadataReference.CreateAssemblyReference("System"))
.AddMetadataReference(projectId, MetadataReference.CreateAssemblyReference("System.Core"))
.AddMetadataReference(projectId, MetadataReference.CreateAssemblyReference("System.Web"))
.AddDocument(projectId, "MyFile.cs",
@"using System.Web;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e, string s)
{
Response.Write(""hello"");
}
}"
, out documentId);
var mydocument = solution.GetDocument(documentId);
var tree = mydocument.GetSyntaxTree();
var model = mydocument.GetSemanticModel();
var responseWriteLine = tree.GetRoot().DescendantNodesAndSelf().First(x => x.GetLocation().GetLineSpan(false).StartLinePosition.Line == 5 && x is InvocationExpressionSyntax);
Assert.IsNotNull(model.GetSymbolInfo(responseWriteLine.Expression).Symbol);