コード例 #1
0
        private static bool TryGetNamingStyle(string title, Dictionary <string, Property> propertyLookup, out NamingStyle namingStyle)
        {
            namingStyle = default;
            if (!TryGetNamingStyleNameForNamingRule(out _))
            {
                return(false);
            }

            namingStyle = new NamingStyle(Guid.NewGuid());
            return(true);

            // Local functions
            bool TryGetNamingStyleNameForNamingRule(out string name)
            {
                if (propertyLookup.TryGetValue($"dotnet_naming_rule.{title}.style", out Property nameProperty))
                {
                    name = nameProperty.Value.Text.Trim();
                    return(name != null);
                }

                name = null;
                return(false);
            }
        }
コード例 #2
0
        private static bool TryGetNamingRule(string title, SymbolSpecification symbolSpecification, NamingStyle namingStyle, Dictionary <string, Property> propertyLookup, out SerializableNamingRule namingRule)
        {
            if (!TryGetRuleSeverity(out ReportDiagnostic enforcementLevel))
            {
                namingRule = null;
                return(false);
            }

            namingRule = new SerializableNamingRule()
            {
                Name                  = title,
                EnforcementLevel      = enforcementLevel,
                NamingStyleID         = namingStyle.ID,
                SymbolSpecificationID = symbolSpecification.ID,
            };
            return(true);

            // Local functions
            bool TryGetRuleSeverity(out ReportDiagnostic severity)
            {
                if (propertyLookup.TryGetValue($"dotnet_naming_rule.{title}.severity", out Property severityProperty))
                {
                    severity = ParseEnforcementLevel(severityProperty?.Value.Text.Trim() ?? string.Empty);
                    return(true);
                }

                severity = default;
                return(false);
            }

            ReportDiagnostic ParseEnforcementLevel(string severity)
            {
                switch (severity.Trim())
                {
                case "none":
                    return(ReportDiagnostic.Suppress);

                case "refactoring":
                case "silent":
                    return(ReportDiagnostic.Hidden);

                case "suggestion":
                    return(ReportDiagnostic.Info);

                case "warning":
                    return(ReportDiagnostic.Warn);

                case "error":
                    return(ReportDiagnostic.Error);

                default:
                    return(ReportDiagnostic.Hidden);
                }
            }
        }