Example #1
0
            public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
            {
                if (node.Modifiers.TryGetSingle(x => x.IsKind(SyntaxKind.VirtualKeyword), out SyntaxToken modifier))
                {
                    node = node.WithModifiers(node.Modifiers.Remove(modifier));
                }

                if (node.Modifiers.TryGetSingle(x => x.IsKind(SyntaxKind.ProtectedKeyword), out modifier))
                {
                    node = node.WithModifiers(node.Modifiers.Replace(modifier, SyntaxFactory.Token(SyntaxKind.PrivateKeyword)));
                }

                return(base.VisitEventDeclaration(node));
            }
Example #2
0
        public static EventDeclarationSyntax InsertModifier(EventDeclarationSyntax eventDeclaration, SyntaxKind modifierKind)
        {
            if (eventDeclaration == null)
            {
                throw new ArgumentNullException(nameof(eventDeclaration));
            }

            return(eventDeclaration.WithModifiers(InsertModifier(eventDeclaration.Modifiers, modifierKind)));
        }
        public static EventDeclarationSyntax AddStaticModifier(EventDeclarationSyntax node)
        {
            if (!node.Modifiers.Contains(SyntaxKind.StaticKeyword))
            {
                return(node.WithModifiers(AddStaticModifier(node.Modifiers)));
            }

            return(node);
        }
Example #4
0
 public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
 {
     if (!ShouldPublicize(node.AttributeLists))
     {
         return(base.VisitEventDeclaration(node));
     }
     logger("Publicize event '{0}'", node.Identifier.Text);
     return(node
            .WithModifiers(MakePublic(node.Modifiers)));
 }
Example #5
0
        public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
        {
            var shouldRemoveModifier = ShouldRemoveModifier(node);

            node = (EventDeclarationSyntax)base.VisitEventDeclaration(node);

            if (shouldRemoveModifier)
            {
                // If this is a top level member, remove the modifier keyword as it's not needed
                node = node.WithModifiers(SyntaxFactory.TokenList(node.Modifiers.Where(IsImportantTypeModifier)));
            }

            return(node);
        }
Example #6
0
        /// <inheritdoc />
        public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
        {
            if (node is null)
            {
                throw new System.ArgumentNullException(nameof(node));
            }

            if (TryUpdate(node.Modifiers, out var modifiers))
            {
                node = node.WithModifiers(modifiers);
            }

            return(base.VisitEventDeclaration(node));
        }
Example #7
0
        public static EventDeclarationSyntax InsertModifier(EventDeclarationSyntax eventDeclaration, SyntaxToken modifier, IModifierComparer comparer)
        {
            if (eventDeclaration == null)
            {
                throw new ArgumentNullException(nameof(eventDeclaration));
            }

            SyntaxTokenList modifiers = eventDeclaration.Modifiers;

            if (!modifiers.Any())
            {
                SyntaxToken eventKeyword = eventDeclaration.EventKeyword;

                return(eventDeclaration
                       .WithEventKeyword(eventKeyword.WithoutLeadingTrivia())
                       .WithModifiers(TokenList(modifier.WithLeadingTrivia(eventKeyword.LeadingTrivia))));
            }

            return(eventDeclaration.WithModifiers(modifiers.InsertModifier(modifier, comparer)));
        }
Example #8
0
 static EventDeclarationSyntax WithPublicModifier(this EventDeclarationSyntax syntax) =>
 syntax.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword)));
Example #9
0
 public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
 {
     node = node.WithModifiers(RemoveDefaultAccessModifier2(node.Modifiers));
     return(base.VisitEventDeclaration(node));
 }
        public static SyntaxNode RemoveModifierFromNode(SyntaxNode node, SyntaxKind modifier)
        {
            //there seem to be no base classes to support WithModifiers.
            //dynamic modifiersNode = node;
            //return modifiersNode.WithModifiers(SyntaxFactory.TokenList(modifiersNode.Modifiers.Where(m => !m.IsKind(SyntaxKind.PrivateKeyword))));

            MethodDeclarationSyntax methodNode = node as MethodDeclarationSyntax;

            if (methodNode != null)
            {
                return(methodNode.WithModifiers(SyntaxFactory.TokenList(methodNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(methodNode.GetLeadingTrivia()));
            }

            FieldDeclarationSyntax fieldNode = node as FieldDeclarationSyntax;

            if (fieldNode != null)
            {
                return(fieldNode.WithModifiers(SyntaxFactory.TokenList(fieldNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(fieldNode.GetLeadingTrivia()));
            }

            PropertyDeclarationSyntax propertyNode = node as PropertyDeclarationSyntax;

            if (propertyNode != null)
            {
                return(propertyNode.WithModifiers(SyntaxFactory.TokenList(propertyNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(propertyNode.GetLeadingTrivia()));
            }

            IndexerDeclarationSyntax indexerNode = node as IndexerDeclarationSyntax;

            if (indexerNode != null)
            {
                return(indexerNode.WithModifiers(SyntaxFactory.TokenList(indexerNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(indexerNode.GetLeadingTrivia()));
            }

            EventDeclarationSyntax eventNode = node as EventDeclarationSyntax;

            if (eventNode != null)
            {
                return(eventNode.WithModifiers(SyntaxFactory.TokenList(eventNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(eventNode.GetLeadingTrivia()));
            }

            ConstructorDeclarationSyntax ctrNode = node as ConstructorDeclarationSyntax;

            if (ctrNode != null)
            {
                return(ctrNode.WithModifiers(SyntaxFactory.TokenList(ctrNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(ctrNode.GetLeadingTrivia()));
            }

            OperatorDeclarationSyntax opNode = node as OperatorDeclarationSyntax;

            if (opNode != null)
            {
                return(opNode.WithModifiers(SyntaxFactory.TokenList(opNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(opNode.GetLeadingTrivia()));
            }

            ClassDeclarationSyntax classNode = node as ClassDeclarationSyntax;

            if (classNode != null)
            {
                return(classNode.WithModifiers(SyntaxFactory.TokenList(classNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(classNode.GetLeadingTrivia()));
            }

            InterfaceDeclarationSyntax interfaceNode = node as InterfaceDeclarationSyntax;

            if (interfaceNode != null)
            {
                return(interfaceNode.WithModifiers(SyntaxFactory.TokenList(interfaceNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(interfaceNode.GetLeadingTrivia()));
            }

            StructDeclarationSyntax structNode = node as StructDeclarationSyntax;

            if (structNode != null)
            {
                return(structNode.WithModifiers(SyntaxFactory.TokenList(structNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(structNode.GetLeadingTrivia()));
            }

            var enumNode = node as EnumDeclarationSyntax;

            if (enumNode != null)
            {
                return(enumNode.WithModifiers(SyntaxFactory.TokenList(enumNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(enumNode.GetLeadingTrivia()));
            }

            var delegateNode = node as DelegateDeclarationSyntax;

            if (delegateNode != null)
            {
                return(delegateNode.WithModifiers(SyntaxFactory.TokenList(delegateNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(delegateNode.GetLeadingTrivia()));
            }
            return(node);
        }