public static bool IsEnabled( this SyntaxNodeAnalysisContext context, ConfigOptionDescriptor option, bool?defaultValue = null) { return(IsEnabled(context.Options, option, context.Node.SyntaxTree, defaultValue)); }
public static bool TryGetOptionAsBool( this SyntaxNodeAnalysisContext context, ConfigOptionDescriptor option, out bool result) { return(TryGetOptionAsBool(context.Options, option, context.Node.SyntaxTree, out result)); }
public static int GetOptionAsInt( this AnalyzerOptions analyzerOptions, ConfigOptionDescriptor option, SyntaxTree syntaxTree, int defaultValue) { return((TryGetOptionAsInt(analyzerOptions, option, syntaxTree, out int result)) ? result : defaultValue); }
public static string GetValue(AnalyzerConfigOptions configOptions, ConfigOptionDescriptor option, string defaultValue = null) { if (configOptions.TryGetValue(option.Key, out string value)) { return(value); } return(defaultValue ?? CodeAnalysisConfig.Instance.EditorConfig.Options.GetValueOrDefault(option.Key) ?? option.DefaultValue); }
public static bool?GetValueAsBool(AnalyzerConfigOptions configOptions, ConfigOptionDescriptor option, bool?defaultValue = null) { if (configOptions.TryGetValue(option.Key, out string rawValue) && bool.TryParse(rawValue, out bool boolValue)) { return(boolValue); } return(defaultValue ?? CodeAnalysisConfig.Instance.GetOptionAsBool(option.Key) ?? option.DefaultValueAsBool); }
public static bool TryGetValue(AnalyzerConfigOptions configOptions, ConfigOptionDescriptor option, out string value, string defaultValue = null) { if (configOptions.TryGetValue(option.Key, out string rawValue)) { value = rawValue; return(true); } value = defaultValue ?? CodeAnalysisConfig.Instance.EditorConfig.Options.GetValueOrDefault(option.Key) ?? option.DefaultValue; return(value != null); }
protected static bool TryReportRequiredOptionNotSet( SyntaxTreeAnalysisContext context, AnalyzerConfigOptions configOptions, DiagnosticDescriptor descriptor, ConfigOptionDescriptor option) { if (!IsOptionSet(configOptions, option)) { ReportDiagnostic(context, descriptor); return(true); } return(false); }
public static bool TryGetOptionAsInt( this AnalyzerOptions analyzerOptions, ConfigOptionDescriptor option, SyntaxTree syntaxTree, out int result) { if (analyzerOptions .AnalyzerConfigOptionsProvider .GetOptions(syntaxTree) .TryGetValue(option.Key, out string rawValue) && int.TryParse(rawValue, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.CurrentCulture, out int value)) { result = value; return(true); } result = default; return(false); }
public static bool TryGetOptionAsBool( this AnalyzerOptions analyzerOptions, ConfigOptionDescriptor option, SyntaxTree syntaxTree, out bool result) { if (analyzerOptions .AnalyzerConfigOptionsProvider .GetOptions(syntaxTree) .TryGetValue(option.Key, out string rawValue) && bool.TryParse(rawValue, out bool value)) { result = value; return(true); } result = default; return(false); }
public static bool IsEnabled( this AnalyzerOptions analyzerOptions, ConfigOptionDescriptor option, SyntaxTree syntaxTree, bool?defaultValue = null) { if (analyzerOptions .AnalyzerConfigOptionsProvider .GetOptions(syntaxTree) .TryGetValue(option.Key, out string value) && bool.TryParse(value, out bool result)) { return(result); } return(defaultValue ?? CodeAnalysisConfig.Instance.GetOptionAsBool(option.Key) ?? option.DefaultValueAsBool ?? false); }
protected static bool TryReportObsoleteOption( SyntaxTreeAnalysisContext context, AnalyzerConfigOptions configOptions, LegacyConfigOptionDescriptor legacyOption, ConfigOptionDescriptor newOption, string newValue) { if (configOptions.IsEnabled(legacyOption)) { DiagnosticHelpers.ReportDiagnostic( context, CommonDiagnosticRules.AnalyzerOptionIsObsolete, Location.None, legacyOption.Key, $", use option '{newOption.Key} = {newValue}' instead"); return(true); } return(false); }
public static bool TryGetValueAsBool(AnalyzerConfigOptions configOptions, ConfigOptionDescriptor option, out bool value, bool?defaultValue = null) { if (configOptions.TryGetValue(option.Key, out string rawValue) && bool.TryParse(rawValue, out bool boolValue)) { value = boolValue; return(true); } bool?maybeValue = defaultValue ?? CodeAnalysisConfig.Instance.GetOptionAsBool(option.Key) ?? option.DefaultValueAsBool; if (maybeValue != null) { value = maybeValue.Value; return(true); } value = false; return(false); }
private static bool IsOptionSet(AnalyzerConfigOptions configOptions, ConfigOptionDescriptor option) { return(configOptions.TryGetValue(option.Key, out string _) || CodeAnalysisConfig.Instance.EditorConfig.Options.ContainsKey(option.Key)); }
internal static bool TryGetValueAsBool(this AnalyzerConfigOptions analyzerConfigOptions, ConfigOptionDescriptor option, out bool value) { return(TryGetValueAsBool(analyzerConfigOptions, option.Key, out value)); }
internal static bool ContainsKey(this AnalyzerConfigOptions analyzerConfigOptions, ConfigOptionDescriptor option) { return(analyzerConfigOptions.TryGetValue(option.Key, out string _)); }
internal static bool IsEnabled(this AnalyzerConfigOptions analyzerConfigOptions, ConfigOptionDescriptor option) { return(analyzerConfigOptions.TryGetValue(option.Key, out string rawValue) && bool.TryParse(rawValue, out bool value) && value); }