diff --git a/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs b/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs index a208cbd2c6..ab08407336 100644 --- a/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs +++ b/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs @@ -49,8 +49,8 @@ public static class ConfigParser [SuppressMessage("ReSharper", "StringLiteralTypo")] [SuppressMessage("ReSharper", "CoVariantArrayConversion")] - private static readonly IReadOnlyDictionary AvailableExporters = - new Dictionary(StringComparer.InvariantCultureIgnoreCase) + private static readonly Dictionary AvailableExporters = + new (StringComparer.InvariantCultureIgnoreCase) { { "csv", new[] { CsvExporter.Default } }, { "csvmeasurements", new[] { CsvMeasurementsExporter.Default } }, @@ -70,6 +70,39 @@ public static class ConfigParser { "fullxml", new[] { XmlExporter.Full } } }; + public static void RegisterCustomExporter(string commandLineName, IExporter exporter) + { + if (!AvailableExporters.TryGetValue(commandLineName, out var array)) + { + AvailableExporters[commandLineName] = new[] { exporter }; + return; + } + AvailableExporters[commandLineName] = new IExporter[array.Length + 1]; + for (int i = 0; i < array.Length; i++) + { + AvailableExporters[commandLineName][i] = array[i]; + } + AvailableExporters[commandLineName][array.Length] = exporter; + } + + public static void RegisterCustomExporter(string commandLineName, IExporter[] exporters) + { + if (!AvailableExporters.TryGetValue(commandLineName, out var array)) + { + AvailableExporters[commandLineName] = (IExporter[])exporters.Clone(); + return; + } + AvailableExporters[commandLineName] = new IExporter[array.Length + exporters.Length]; + for (int i = 0; i < array.Length; i++) + { + AvailableExporters[commandLineName][i] = array[i]; + } + for (int i = 0; i < exporters.Length; i++) + { + AvailableExporters[commandLineName][i+array.Length] = exporters[i]; + } + } + public static (bool isSuccess, IConfig config, CommandLineOptions options) Parse(string[] args, ILogger logger, IConfig globalConfig = null) { (bool isSuccess, IConfig config, CommandLineOptions options) result = default;