Пример #1
0
        private void SymbolAction(SymbolAnalysisContext context)
        {
            var namingStyleRules = context.GetNamingStyleRulesAsync().GetAwaiter().GetResult();

            if (namingStyleRules == null)
            {
                return;
            }

            if (namingStyleRules.TryGetApplicableRule(context.Symbol, out var applicableRule))
            {
                if (applicableRule.EnforcementLevel != DiagnosticSeverity.Hidden &&
                    !applicableRule.IsNameCompliant(context.Symbol.Name, out var failureReason))
                {
                    var descriptor = new DiagnosticDescriptor(IDEDiagnosticIds.NamingRuleId,
                                                              s_localizableTitleNamingStyle,
                                                              string.Format(FeaturesResources.Naming_rule_violation_0, failureReason),
                                                              DiagnosticCategory.Style,
                                                              applicableRule.EnforcementLevel,
                                                              isEnabledByDefault: true);

                    var builder = ImmutableDictionary.CreateBuilder <string, string>();
                    builder[nameof(NamingStyle)] = applicableRule.NamingStyle.CreateXElement().ToString();
                    builder["OptionName"]        = nameof(SimplificationOptions.NamingPreferences);
                    builder["OptionLanguage"]    = context.Compilation.Language;
                    context.ReportDiagnostic(Diagnostic.Create(descriptor, context.Symbol.Locations.First(), builder.ToImmutable()));
                }
            }
        }