public override Accessibility GetAccessibility(MethodDeclarationSyntax declaration)
            {
                if (declaration == null)
                {
                    throw new ArgumentNullException(nameof(declaration));
                }

                SyntaxTokenList modifiers = declaration.Modifiers;

                if (modifiers.Contains(SyntaxKind.PartialKeyword))
                {
                    return(Accessibility.Private);
                }

                if (declaration.ExplicitInterfaceSpecifier != null)
                {
                    return(Accessibility.Private);
                }

                if (declaration.IsParentKind(SyntaxKind.InterfaceDeclaration))
                {
                    return(Accessibility.Public);
                }

                Accessibility accessibility = SyntaxAccessibility.GetExplicitAccessibility(declaration.Modifiers);

                return((accessibility != Accessibility.NotApplicable)
                    ? accessibility
                    : GetDefaultAccessibility(declaration));
            }
            public override Accessibility GetExplicitAccessibility(OperatorDeclarationSyntax declaration)
            {
                if (declaration == null)
                {
                    throw new ArgumentNullException(nameof(declaration));
                }

                return(SyntaxAccessibility.GetExplicitAccessibility(declaration.Modifiers));
            }
            public override Accessibility GetAccessibility(InterfaceDeclarationSyntax declaration)
            {
                if (declaration == null)
                {
                    throw new ArgumentNullException(nameof(declaration));
                }

                Accessibility accessibility = SyntaxAccessibility.GetExplicitAccessibility(declaration.Modifiers);

                return((accessibility != Accessibility.NotApplicable)
                    ? accessibility
                    : GetDefaultAccessibility(declaration));
            }
            public override Accessibility GetAccessibility(AccessorDeclarationSyntax declaration)
            {
                if (declaration == null)
                {
                    throw new ArgumentNullException(nameof(declaration));
                }

                Accessibility accessibility = SyntaxAccessibility.GetExplicitAccessibility(declaration.Modifiers);

                SyntaxNode containingDeclaration = declaration.Parent?.Parent;

                if (containingDeclaration == null)
                {
                    return(accessibility);
                }

                Accessibility containingAccessibility = GetAccessibility();

                if (containingAccessibility == Accessibility.NotApplicable)
                {
                    return(accessibility);
                }

                return((accessibility.IsMoreRestrictiveThan(containingAccessibility))
                    ? accessibility
                    : containingAccessibility);

                Accessibility GetAccessibility()
                {
                    switch (containingDeclaration.Kind())
                    {
                    case SyntaxKind.PropertyDeclaration:
                        return(SyntaxAccessibility <PropertyDeclarationSyntax> .Instance.GetAccessibility((PropertyDeclarationSyntax)containingDeclaration));

                    case SyntaxKind.IndexerDeclaration:
                        return(SyntaxAccessibility <IndexerDeclarationSyntax> .Instance.GetAccessibility((IndexerDeclarationSyntax)containingDeclaration));

                    case SyntaxKind.EventDeclaration:
                        return(SyntaxAccessibility <EventDeclarationSyntax> .Instance.GetAccessibility((EventDeclarationSyntax)containingDeclaration));
                    }

                    Debug.Fail(containingDeclaration.Kind().ToString());

                    return(Accessibility.NotApplicable);
                }
            }
Esempio n. 5
0
            public override Accessibility GetAccessibility(IncompleteMemberSyntax declaration)
            {
                if (declaration == null)
                {
                    throw new ArgumentNullException(nameof(declaration));
                }

                if (declaration.IsParentKind(SyntaxKind.InterfaceDeclaration))
                {
                    return(Accessibility.Public);
                }

                Accessibility accessibility = SyntaxAccessibility.GetExplicitAccessibility(declaration.Modifiers);

                return((accessibility != Accessibility.NotApplicable)
                    ? accessibility
                    : GetDefaultAccessibility(declaration));
            }
            public override Accessibility GetAccessibility(ConstructorDeclarationSyntax declaration)
            {
                if (declaration == null)
                {
                    throw new ArgumentNullException(nameof(declaration));
                }

                SyntaxTokenList modifiers = declaration.Modifiers;

                if (modifiers.Contains(SyntaxKind.StaticKeyword))
                {
                    return(Accessibility.Private);
                }

                Accessibility accessibility = SyntaxAccessibility.GetExplicitAccessibility(modifiers);

                return((accessibility != Accessibility.NotApplicable)
                    ? accessibility
                    : GetDefaultAccessibility(declaration));
            }