Roslyn TypeDeclarationSyntax, MethodDeclarationSyntax, FieldDeclarationSyntax have common properties, but do not have a common base class or interface

What I'm trying to do:

I am writing code refactoring with roslyn. My goal is to cut blanks. So, what I'm doing is basically removing all private employees and replacing the bodies of non-private personnel throw new NotImplementedException().

What is my problem:

Everything works fine, but I got a lot of code duplication:

    private static bool IsPrivate(TypeDeclarationSyntax type)
    {
        return type.Modifiers.Any(IsPrivateModifier);
    }

    private static bool IsPrivate(MethodDeclarationSyntax method)
    {
        return method.Modifiers.Any(IsPrivateModifier);
    }

    private static bool IsPrivate(FieldDeclarationSyntax field)
    {
        return field.Modifiers.Any(IsPrivateModifier);
    }

    private static bool IsPrivate(PropertyDeclarationSyntax property)
    {
        return property.Modifiers.Any(IsPrivateModifier);
    }

    private static bool IsPrivate(IndexerDeclarationSyntax property)
    {
        return property.Modifiers.Any(IsPrivateModifier);
    }

    private static bool IsPrivateModifier(SyntaxToken modifier)
    {
        return modifier.Kind() == SyntaxKind.PrivateKeyword;
    }

The reason is because I need to use a property Members, and there is no base type or interface for the syntax classes that will declare Members. I have the same problem with a property Bodythat is common to all of these, bu there is no common base or common interface.

: , API , - ? - , .


roslyn: # 10455

+4
1

, ,

dynamic 

.

0

All Articles