Example #1
0
        public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
        {
            NamespaceDeclarationSyntax namespaceDeclaration = node.Ancestors().OfType <NamespaceDeclarationSyntax>().FirstOrDefault();

            node = (ClassDeclarationSyntax)base.VisitClassDeclaration(node);

            var classTemplates = new List <AopTemplate>();

            var globalTemplates = _templateService.GetGlobalTemplates(_filePath, namespaceDeclaration?.Name?.ToString(), node.Identifier.ToString());

            classTemplates.AddRange(globalTemplates.Where(w => w.Action == Action));
            classTemplates.ForEach(s => s.AppliedTo = AopTemplateApplied.Class);

            string className = node.Identifier.ToString();

            Console.Out.WriteLine("Class:  " + className);

            if (BuilderSettings.Verbosity > 2)
            {
                Console.Out.WriteLine("Old code:");
                Console.Out.WriteLine(node.ToFullString());
            }

            AopRewriter.AddTemplatesFromAttributes(classTemplates, Action, node.AttributeLists, AopTemplateAction.Methods);

            ClassDeclarationSyntax result = AopRewriter.ProcessTemplates <ClassDeclarationSyntax>(_templateService, classTemplates, node, node);

            return(result);
        }
Example #2
0
        public IEnumerable <AopTemplate> GetPropertyTemplates(PropertyDeclarationSyntax node)
        {
            ClassDeclarationSyntax     classDeclaration     = node.Ancestors().OfType <ClassDeclarationSyntax>().FirstOrDefault();
            NamespaceDeclarationSyntax namespaceDeclaration = classDeclaration.Ancestors().OfType <NamespaceDeclarationSyntax>().FirstOrDefault();

            var propertyTemplates = new List <AopTemplate>();

            var globalTemplate = _templateService.GetGlobalTemplates(_filePath, namespaceDeclaration?.Name?.ToString(), classDeclaration?.Identifier.ToString(), propertyName: node.Identifier.ToString());

            propertyTemplates.AddRange(globalTemplate.Where(w => w.Action == AopTemplateAction.All || w.Action == AopTemplateAction.Properties));

            AddTemplatesFromClass(propertyTemplates, AopTemplateAction.Properties, classDeclaration, node.Identifier.ToString(), node.Modifiers);
            AddTemplatesFromAttributes(propertyTemplates, AopTemplateAction.Properties, node.AttributeLists, AopTemplateAction.Properties);

            if (!String.IsNullOrEmpty(BuilderSettings.OnlyTemplate))
            {
                return(propertyTemplates.Where(w => w.TemplateName == BuilderSettings.OnlyTemplate));
            }

            return(propertyTemplates.OrderBy(o => o.AdvicePriority));
        }