예제 #1
0
        private static ConfigurationHierarchy GetConfigurationHierarchy(this AnalyzerOptions options)
        {
            // TryGetValue upfront to avoid allocating createValueCallback if the entry already exists.
            if (s_cachedOptions.TryGetValue(options, out var categorizedAnalyzerConfigOptions))
            {
                return(categorizedAnalyzerConfigOptions);
            }

            var createValueCallback = new ConditionalWeakTable <AnalyzerOptions, ConfigurationHierarchy> .CreateValueCallback(_ => new ConfigurationHierarchy(GetFromAdditionalFiles()));

            return(s_cachedOptions.GetValue(options, createValueCallback));

            EditorConfigFile GetFromAdditionalFiles()
            {
                foreach (var additionalFile in options.AdditionalFiles)
                {
                    var fileName = Path.GetFileName(additionalFile.Path);
                    if (fileName.Equals(".editorconfig", StringComparison.OrdinalIgnoreCase))
                    {
                        var text = additionalFile.GetText();
                        return(EditorConfigFileParser.Parse(text));
                    }
                }

                return(EditorConfigFile.Empty);
            }
        }
예제 #2
0
 private EditorConfigFile LoadForDirectory(string folderPath)
 {
     return(_configurationFiles.GetOrAdd(folderPath, path =>
     {
         var editorConfigurationPath = Path.Combine(path, ".editorconfig");
         return EditorConfigFileParser.Load(editorConfigurationPath);
     }));
 }