0
我在內存中爲單元測試目的創建了一個工作空間,但我無法訪問某個InvocationExpression的符號信息(這是我測試的CodeIssue所需的)。這是一個失敗測試的簡單例子。請幫忙?在內存中創建的工作空間 - 無法訪問symbolinfo
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);
您正在使用哪種ctp? –