Exemple #1
0
        private static BaseTypeDeclarationSyntax AddGeneratedCodeAttribute(BaseTypeDeclarationSyntax typeDecl)
        {
            AttributeListSyntax attributeListForGeneratedCodeAttribute =
                SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(MakeGeneratedCodeAttribute()));

            var enumDecl = typeDecl as EnumDeclarationSyntax;

            if (enumDecl != null)
            {
                return(enumDecl.AddAttributeLists(attributeListForGeneratedCodeAttribute));
            }

            var classDecl = typeDecl as ClassDeclarationSyntax;

            if (classDecl != null)
            {
                return(classDecl.AddAttributeLists(attributeListForGeneratedCodeAttribute));
            }

            var interfaceDecl = typeDecl as InterfaceDeclarationSyntax;

            if (interfaceDecl != null)
            {
                return(interfaceDecl.AddAttributeLists(attributeListForGeneratedCodeAttribute));
            }

            throw new ArgumentException("Invalid argument type: " + typeDecl.GetType().Name, nameof(typeDecl));
        }
Exemple #2
0
        private static BaseTypeDeclarationSyntax RewriteAccess(BaseTypeDeclarationSyntax declaration)
        {
            switch (declaration)
            {
            case ClassDeclarationSyntax classSyntax: return(classSyntax.WithModifiers(classSyntax.Modifiers.Select(RewriteModifier)));

            case EnumDeclarationSyntax enumSyntax: return(enumSyntax.WithModifiers(enumSyntax.Modifiers.Select(RewriteModifier)));

            case StructDeclarationSyntax structSyntax: return(structSyntax.WithModifiers(structSyntax.Modifiers.Select(RewriteModifier)));

            case InterfaceDeclarationSyntax interfaceSyntax: return(interfaceSyntax.WithModifiers(interfaceSyntax.Modifiers.Select(RewriteModifier)));

            default: throw new Exception($"Not supported top level syntax {declaration.GetType().Name}");
            }
        }