Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
        {
            var propertyDefinitionTranslationUnit = new PropertyDefinitionTranslationUnitFactory(node, this.semanticModel, this.generateTranslationUniOnProtectedMembers).Create();

            if (propertyDefinitionTranslationUnit == null)
            {
                // When the factory returns null, then the member is not exposed, thus we do not generate it in the translation tree
                return;
            }

            this.classDeclaration.AddPropertyDeclaration(propertyDefinitionTranslationUnit);

            this.InvokePropertyDeclarationVisited(this, new WalkerEventArgs());
        }
Example #2
0
        private static void TestScriptNamespaceOnParameter(string source, bool withSemanticModel, string expectedFullName)
        {
            var tree = CSharpSyntaxTree.ParseText(source);

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

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

            Assert.IsNotNull(node);

            var propertyDeclarationNode = node as PropertyDeclarationSyntax;

            Assert.IsNotNull(propertyDeclarationNode);

            var translationUnitFactory = new PropertyDefinitionTranslationUnitFactory(propertyDeclarationNode, semanticModel, true).Create();

            Assert.IsNotNull(translationUnitFactory, "Translation unit expected to be created!");

            var propertyTranslationUnit = (translationUnitFactory as PropertyDefinitionTranslationUnit);

            Assert.IsNotNull(propertyTranslationUnit, $"Expecting a translation unit of type {typeof(PropertyDefinitionTranslationUnit).Name}!");

            var translationUnit = MockedPropertyDefinitionTranslationUnit.Create(propertyTranslationUnit);

            Assert.IsNotNull(translationUnit.Type);

            var typeIdentifierTranslationUnit = translationUnit.Type as TypeIdentifierTranslationUnit;

            Assert.IsNotNull(typeIdentifierTranslationUnit, $"Expected argument to be of type {typeof(TypeIdentifierTranslationUnit).Name}");

            var typeFullName = typeIdentifierTranslationUnit.Translate();

            Assert.AreEqual(expectedFullName, typeFullName, "Expected ScriptNamespace overriden type to be used!");
        }