Class BenchmarkWorkspaceOptionsExtensions
- Namespace
- Codebelt.Extensions.BenchmarkDotNet
- Assembly
- Codebelt.Extensions.BenchmarkDotNet.dll
Extension methods for the BenchmarkWorkspaceOptions class.
public static class BenchmarkWorkspaceOptionsExtensions
- Inheritance
-
BenchmarkWorkspaceOptionsExtensions
Methods
ConfigureBenchmarkDotNet(BenchmarkWorkspaceOptions, Func<IConfig, IConfig>)
Configures the BenchmarkDotNet configuration for the specified options.
public static BenchmarkWorkspaceOptions ConfigureBenchmarkDotNet(this BenchmarkWorkspaceOptions options, Func<IConfig, IConfig> configure)
Parameters
optionsBenchmarkWorkspaceOptionsThe BenchmarkWorkspaceOptions to extend.
configureFunc<IConfig, IConfig>The function delegate that configures the BenchmarkDotNet.Configs.IConfig.
Returns
- BenchmarkWorkspaceOptions
The
optionsinstance for chaining.
Remarks
BenchmarkDotNet's configuration model is intentionally immutable-ish: methods such as
AddJob, AddColumn, and AddDiagnoser do not mutate the
incoming BenchmarkDotNet.Configs.IConfig instance. Instead, they produce and return a new
configuration object. This behavior is powerful but can be unintuitive when used inside
option delegates where callers naturally expect fluent configuration to modify the
underlying options instance.
Without this helper, callers would need to explicitly reassign:
options.Configuration = options.Configuration.AddJob(job);
This extension method abstracts away that requirement by:
- Forcing initialization of the default configuration if needed,
- Passing the current configuration to the delegate for fluent BenchmarkDotNet operations,
- Assigning the delegate’s returned configuration back to Configuration.
This preserves BenchmarkDotNet's design while providing an intuitive experience for users configuring BenchmarkWorkspaceOptions via delegates.
Exceptions
- ArgumentNullException
optionscannot be null -or-configurecannot be null.- InvalidOperationException
configuremust not return null.- ArgumentNullException
optionscannot be null -or-configurecannot be null.- InvalidOperationException
configuremust not return null.