コード例 #1
0
        public void ScriptNamespaceRetrievedOnConstructorArgumentType()
        {
            var tree = CSharpSyntaxTree.ParseText(@"
            namespace Namespace1 {
                [ScriptNamespace(""OverridenNamespace"")]
                public class Class1 { }
                public class Class2 {
                    public Class2(Class1 parameter) { }
                }
            }
            ");

            // Loading MSCoreLib
            var semanticModel = (CSharpCompilation.Create("TestAssembly")
                                 .AddReferences(
                                     MetadataReference.CreateFromFile(
                                         typeof(object).Assembly.Location))
                                 .AddSyntaxTrees(tree).AddScriptNamespaceReference().GetSemanticModel(tree));

            var node = new NodeLocator(tree).LocateFirst(typeof(ConstructorDeclarationSyntax));

            Assert.IsNotNull(node);

            var ctorDeclarationNode = node as ConstructorDeclarationSyntax;

            Assert.IsNotNull(ctorDeclarationNode);

            var parameters = new ConstructorDeclaration(ctorDeclarationNode, semanticModel).Parameters;

            Assert.AreEqual(1, parameters.Count(), "1 argument expected");
            var typeReference = parameters.ElementAt(0).Type;

            Assert.AreEqual("OverridenNamespace.Class1", typeReference.FullName, "ScriptNamespace overriden namespace not detected!");
        }