Beispiel #1
0
        /// <summary>
        /// This method we will write a diagnostic if name:
        /// contains two consecutive upper case characters or
        /// does not start with at least two lower case characters
        /// ends with an uppercase character.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="name">The name.</param>
        /// <param name="location">An instance of <see cref="Location"/> containing the location of the issue.</param>
        /// <param name="rule">An instance of <see cref="DiagnosticDescriptor"/> that contains the rule details.</param>
        /// <returns><c>true</c> if the diagnostic rule has been broken, otherwise <c>false</c>.</returns>
        public static bool DoesNotSatisfyLocalVariableNameRule(SyntaxNodeAnalysisContext context, string name, Location location, DiagnosticDescriptor rule)
        {
            var analysed = false;

            if (MatchFound(@"[A-Z]{2,}", name) || !MatchFound(@"^[a-z]{2,}", name) || MatchFound(@"[A-Z]$", name))
            {
                DiagnosticsManager.CreateNamingConventionDiagnostic(context, location, rule, $"{name} does not satisfy naming convention. \n{name} must start with at least two lower case character, \nnot end with uppercase character and not contain two consecutive upper case characters.");
                analysed = true;
            }

            return(analysed);
        }
Beispiel #2
0
        /// <summary>
        /// This method we will write a diagnostic if name:
        /// does not begin with upper case character I, uppercase character and any other lowercase characters
        /// contains two consecutive upper case characters after the first two upper case  characters
        /// ends with an uppercase character.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="name">The name.</param>
        /// <param name="location">An instance of <see cref="Location"/> containing the location of the issue.</param>
        /// <param name="rule">An instance of <see cref="DiagnosticDescriptor"/> that contains the rule details.</param>
        /// <returns><c>true</c> if the diagnostic rule has been broken, otherwise <c>false</c>.</returns>
        public static bool DoesNotSatisfyInterfaceRule(SyntaxNodeAnalysisContext context, string name, Location location, DiagnosticDescriptor rule)
        {
            var analysed = false;

            if (!MatchFound(@"^I[A-Z][a-z]", name) || MatchFound(@"^I[A-Z](.)*[A-Z]{2,}", name) || MatchFound(@"[A-Z]$", name))
            {
                DiagnosticsManager.CreateNamingConventionDiagnostic(context, location, rule, $"{name} does not satisfy naming convention. \n{name} must start with character I and an upper case character, \nnot end with uppercase character and not contain two consecutive upper case characters apart from the first two characters.");
                analysed = true;
            }

            return(analysed);
        }