Example #1
0
        public static T GetOption <T>(this AnalyzerOptions analyzerOptions, IOption2 option, string?language, SyntaxTree syntaxTree, CancellationToken cancellationToken)
        {
            if (analyzerOptions.TryGetEditorConfigOption <T>(option, syntaxTree, out var value))
            {
                return(value);
            }

            return((T)option.DefaultValue !);
        }
Example #2
0
#pragma warning disable IDE0060 // Remove unused parameter - Needed to share this method signature between CodeStyle and Features layer.
        public static T GetOption <T>(this AnalyzerOptions analyzerOptions, IOption2 option, string?language, SyntaxTree syntaxTree, CancellationToken cancellationToken)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            if (analyzerOptions.TryGetEditorConfigOption <T>(option, syntaxTree, out var value))
            {
                return(value);
            }

            return((T)option.DefaultValue !);
        }
Example #3
0
        public static async ValueTask <T> GetOptionAsync <T>(this AnalyzerOptions analyzerOptions, IOption option, string?language, SyntaxTree syntaxTree, CancellationToken cancellationToken)
        {
            if (analyzerOptions.TryGetEditorConfigOption <T>(option, syntaxTree, out var value))
            {
                return(value);
            }

#pragma warning disable CS0612 // Type or member is obsolete
            var optionSet = await analyzerOptions.GetDocumentOptionSetAsync(syntaxTree, cancellationToken).ConfigureAwait(false);

#pragma warning restore CS0612 // Type or member is obsolete

            if (optionSet != null)
            {
                value = optionSet.GetOption <T>(new OptionKey(option, language));
            }

            return(value ?? (T)option.DefaultValue !);
        }