Пример #1
0
        /// <summary>
        /// Check is member is present in the given region
        /// </summary>
        /// <param name="member"></param>
        /// <param name="locationRange"></param>
        /// <returns>true if member is inside the given region, else false</returns>
        private static bool MemberPresentInRegion(MemberDeclarationSyntax member, LocationRangeModel locationRange)
        {
            int memberLocation = GetMemberLineNumber(member.GetLocation());

            if (memberLocation > locationRange.StartLine && memberLocation < locationRange.EndLine)
            {
                return(true);
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Verify member belongs to Non-Public Data Member Region
        /// if member is of type method, throw an error
        /// if member is of type field, check if it is non-public
        /// </summary>
        /// <param name="member"></param>
        /// <param name="locationRange"></param>
        /// <param name="context"></param>
        private static void VerifyMemberForNonPublicDataMemberRegion(MemberDeclarationSyntax member, LocationRangeModel locationRange, SyntaxNodeAnalysisContext context)
        {
            SyntaxTokenList modifiers     = default(SyntaxTokenList);
            bool            shouldProcess = false;

            switch (member.Kind())
            {
            case SyntaxKind.FieldDeclaration:
                modifiers     = ((FieldDeclarationSyntax)member).Modifiers;
                shouldProcess = true;
                break;

            case SyntaxKind.EnumDeclaration:
                modifiers     = ((EnumDeclarationSyntax)member).Modifiers;
                shouldProcess = true;
                break;

            case SyntaxKind.DelegateDeclaration:
                modifiers     = ((DelegateDeclarationSyntax)member).Modifiers;
                shouldProcess = true;
                break;
            }

            if (shouldProcess)
            {
                if (!HasAccessModifier(modifiers))
                {
                    return;
                }
                else if (MemberIsPublic(modifiers))
                {
                    CreateDiagnostic(member.GetLocation(), context, NonPublicDataMembersRegion, EnforceMemberLocation);
                }
                return;
            }

            if (member.Kind() == SyntaxKind.StructDeclaration)
            {
                return;
            }

            switch (member.Kind())
            {
            case SyntaxKind.ConstructorDeclaration:
            case SyntaxKind.MethodDeclaration:
            case SyntaxKind.PropertyDeclaration:
            case SyntaxKind.EventDeclaration:
            case SyntaxKind.EventFieldDeclaration:
            case SyntaxKind.OperatorDeclaration:
            case SyntaxKind.ClassDeclaration:
            case SyntaxKind.IndexerDeclaration:
            case SyntaxKind.DestructorDeclaration:
                CreateDiagnostic(member.GetLocation(), context, NonPublicDataMembersRegion, EnforceMemberLocation);
                break;

            default:
                CreateDiagnostic(member.GetLocation(), context, NonPublicDataMembersRegion, NonCheckedMember);
                break;
            }
        }
Пример #3
0
 /// <summary>
 /// Check whether the members of Non-Public Data Members Region belong there
 /// </summary>
 /// <param name="members"></param>
 /// <param name="locationRange"></param>
 /// <param name="context"></param>
 /// <returns>Dummy return</returns>
 private static bool CheckMembersOfNonPublicDataMembersRegion(List <MemberDeclarationSyntax> members, LocationRangeModel locationRange, SyntaxNodeAnalysisContext context)
 {
     foreach (MemberDeclarationSyntax member in members)
     {
         VerifyMemberForNonPublicDataMemberRegion(member, locationRange, context);
     }
     return(true);
 }
Пример #4
0
        /// <summary>
        /// Filters the list of members based on their location with respect to the given region
        /// </summary>
        /// <param name="members">List of members</param>
        /// <param name="locationRange">LocationRangeModel object</param>
        /// <returns>List of members belonging to the given region</returns>
        private static List <MemberDeclarationSyntax> GetMembersOfRegion(SyntaxList <MemberDeclarationSyntax> members, LocationRangeModel locationRange)
        {
            List <MemberDeclarationSyntax> filteredMembers = new List <MemberDeclarationSyntax>();

            foreach (MemberDeclarationSyntax member in members)
            {
                if (MemberPresentInRegion(member, locationRange))
                {
                    filteredMembers.Add(member);
                }
            }
            return(filteredMembers);
        }