0

単体テストの目的でメモリ内にワークスペースを作成していますが、特定の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);
4

1 に答える 1

3

欠落していたコード スニペットにいくつかの使用法を追加しました。

 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;
                        using System.Web;
                        using System.Web.UI;

                        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();
            SemanticModel model = (SemanticModel)mydocument.GetSemanticModel();

            var responseWriteLine = tree.GetRoot().DescendantNodes().OfType<InvocationExpressionSyntax>().First();
            Assert.IsNotNull(model.GetSymbolInfo(responseWriteLine.Expression).Symbol);
于 2012-12-12T06:45:59.970 に答える