public static CompilationCategorizedAnalyzerConfigOptions Parse(SourceText text) { var parsedOptions = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (var textLine in text.Lines) { var line = textLine.ToString(); if (string.IsNullOrWhiteSpace(line) || IsComment(line)) { continue; } var propMatches = s_propertyMatcher.Matches(line); if (propMatches.Count > 0 && propMatches[0].Groups.Count > 1) { var key = propMatches[0].Groups[1].Value; var value = propMatches[0].Groups[2].Value; Debug.Assert(!string.IsNullOrEmpty(key)); Debug.Assert(key == key.Trim()); Debug.Assert(value == value.Trim()); key = CaseInsensitiveComparison.ToLower(key); if (s_reservedKeys.Contains(key) || s_reservedValues.Contains(value)) { value = CaseInsensitiveComparison.ToLower(value); } parsedOptions[key] = value; continue; } } return(CompilationCategorizedAnalyzerConfigOptions.Create(parsedOptions)); }
public static AggregateCategorizedAnalyzerConfigOptions Create(AnalyzerConfigOptionsProvider analyzerConfigOptionsProvider, Compilation compilation, CompilationCategorizedAnalyzerConfigOptions additionalFileBasedOptions) { analyzerConfigOptionsProvider = analyzerConfigOptionsProvider ?? throw new ArgumentNullException(nameof(analyzerConfigOptionsProvider)); additionalFileBasedOptions = additionalFileBasedOptions ?? throw new ArgumentNullException(nameof(additionalFileBasedOptions)); if (analyzerConfigOptionsProvider.IsEmpty() && additionalFileBasedOptions.IsEmpty) { return(Empty); } Lazy <SyntaxTreeCategorizedAnalyzerConfigOptions>?globalOptions; #if CODEANALYSIS_V3_7_OR_BETTER globalOptions = new Lazy <SyntaxTreeCategorizedAnalyzerConfigOptions>(() => SyntaxTreeCategorizedAnalyzerConfigOptions.Create(analyzerConfigOptionsProvider.GlobalOptions)); #else globalOptions = null; #endif var perTreeOptionsBuilder = PooledDictionary <SyntaxTree, Lazy <SyntaxTreeCategorizedAnalyzerConfigOptions> > .GetInstance(); foreach (var tree in compilation.SyntaxTrees) { perTreeOptionsBuilder.Add(tree, new Lazy <SyntaxTreeCategorizedAnalyzerConfigOptions>(() => Create(tree, analyzerConfigOptionsProvider))); } return(new AggregateCategorizedAnalyzerConfigOptions(globalOptions, perTreeOptionsBuilder.ToImmutableDictionaryAndFree(), additionalFileBasedOptions));
private AggregateCategorizedAnalyzerConfigOptions(Lazy <SyntaxTreeCategorizedAnalyzerConfigOptions>?globalOptions, ImmutableDictionary <SyntaxTree, Lazy <SyntaxTreeCategorizedAnalyzerConfigOptions> > perTreeOptions, CompilationCategorizedAnalyzerConfigOptions additionalFileBasedOptions) { _globalOptions = globalOptions; _perTreeOptions = perTreeOptions; _additionalFileBasedOptions = additionalFileBasedOptions; }