コード例 #1
0
 public static bool IsEnabled(
     this SyntaxNodeAnalysisContext context,
     ConfigOptionDescriptor option,
     bool?defaultValue = null)
 {
     return(IsEnabled(context.Options, option, context.Node.SyntaxTree, defaultValue));
 }
コード例 #2
0
 public static bool TryGetOptionAsBool(
     this SyntaxNodeAnalysisContext context,
     ConfigOptionDescriptor option,
     out bool result)
 {
     return(TryGetOptionAsBool(context.Options, option, context.Node.SyntaxTree, out result));
 }
コード例 #3
0
 public static int GetOptionAsInt(
     this AnalyzerOptions analyzerOptions,
     ConfigOptionDescriptor option,
     SyntaxTree syntaxTree,
     int defaultValue)
 {
     return((TryGetOptionAsInt(analyzerOptions, option, syntaxTree, out int result))
         ? result
         : defaultValue);
 }
コード例 #4
0
ファイル: ConfigOptions.cs プロジェクト: skyhoshi/Roslynator
        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);
        }
コード例 #5
0
ファイル: ConfigOptions.cs プロジェクト: skyhoshi/Roslynator
        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);
        }
コード例 #6
0
ファイル: ConfigOptions.cs プロジェクト: skyhoshi/Roslynator
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: ConfigOptions.cs プロジェクト: skyhoshi/Roslynator
        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);
        }
コード例 #13
0
 private static bool IsOptionSet(AnalyzerConfigOptions configOptions, ConfigOptionDescriptor option)
 {
     return(configOptions.TryGetValue(option.Key, out string _) ||
            CodeAnalysisConfig.Instance.EditorConfig.Options.ContainsKey(option.Key));
 }
コード例 #14
0
 internal static bool TryGetValueAsBool(this AnalyzerConfigOptions analyzerConfigOptions, ConfigOptionDescriptor option, out bool value)
 {
     return(TryGetValueAsBool(analyzerConfigOptions, option.Key, out value));
 }
コード例 #15
0
 internal static bool ContainsKey(this AnalyzerConfigOptions analyzerConfigOptions, ConfigOptionDescriptor option)
 {
     return(analyzerConfigOptions.TryGetValue(option.Key, out string _));
 }
コード例 #16
0
 internal static bool IsEnabled(this AnalyzerConfigOptions analyzerConfigOptions, ConfigOptionDescriptor option)
 {
     return(analyzerConfigOptions.TryGetValue(option.Key, out string rawValue) &&
            bool.TryParse(rawValue, out bool value) &&
            value);
 }