Exemple #1
0
        internal static AccessLevel GetAccessLevelForOrdering(SyntaxNode member, SyntaxTokenList modifiers)
        {
            SyntaxKind type = member.Kind();

            AccessLevel accessibility;

            if ((type == SyntaxKind.ConstructorDeclaration && modifiers.Any(SyntaxKind.StaticKeyword)) ||
                (type == SyntaxKind.MethodDeclaration && ((MethodDeclarationSyntax)member).ExplicitInterfaceSpecifier != null) ||
                (type == SyntaxKind.PropertyDeclaration && ((PropertyDeclarationSyntax)member).ExplicitInterfaceSpecifier != null) ||
                (type == SyntaxKind.IndexerDeclaration && ((IndexerDeclarationSyntax)member).ExplicitInterfaceSpecifier != null))
            {
                accessibility = AccessLevel.Public;
            }
            else
            {
                accessibility = AccessLevelHelper.GetAccessLevel(modifiers);
                if (accessibility == AccessLevel.NotSpecified)
                {
                    if (member.Parent.IsKind(SyntaxKind.CompilationUnit) || member.Parent.IsKind(SyntaxKind.NamespaceDeclaration))
                    {
                        accessibility = AccessLevel.Internal;
                    }
                    else
                    {
                        accessibility = AccessLevel.Private;
                    }
                }
            }

            return(accessibility);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemberOrderHelper"/> struct.
        /// </summary>
        /// <param name="member">The member to wrap.</param>
        /// <param name="checks">The element ordering checks.</param>
        internal MemberOrderHelper(MemberDeclarationSyntax member, ElementOrderingChecks checks)
        {
            this.Member = member;
            var modifiers = member.GetModifiers();
            var type      = member.Kind();

            type = type == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : type;

            this.elementPriority = checks.ElementType ? TypeMemberOrder.IndexOf(type) : 0;
            this.modifierFlags   = GetModifierFlags(modifiers, checks);
            if (checks.AccessLevel)
            {
                if ((type == SyntaxKind.ConstructorDeclaration && this.modifierFlags.HasFlag(ModifierFlags.Static)) ||
                    (type == SyntaxKind.MethodDeclaration && ((MethodDeclarationSyntax)member).ExplicitInterfaceSpecifier != null) ||
                    (type == SyntaxKind.PropertyDeclaration && ((PropertyDeclarationSyntax)member).ExplicitInterfaceSpecifier != null) ||
                    (type == SyntaxKind.IndexerDeclaration && ((IndexerDeclarationSyntax)member).ExplicitInterfaceSpecifier != null))
                {
                    this.accessibilty = AccessLevel.Public;
                }
                else
                {
                    this.accessibilty = AccessLevelHelper.GetAccessLevel(modifiers);
                    if (this.accessibilty == AccessLevel.NotSpecified)
                    {
                        if (member.Parent.IsKind(SyntaxKind.CompilationUnit) || member.Parent.IsKind(SyntaxKind.NamespaceDeclaration))
                        {
                            this.accessibilty = AccessLevel.Internal;
                        }
                        else
                        {
                            this.accessibilty = AccessLevel.Private;
                        }
                    }
                }
            }
            else
            {
                this.accessibilty = AccessLevel.Public;
            }
        }