Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow ArgumentsSource to reference methods in other types #2744

Closed
@JimmyCushnie

Description

@JimmyCushnie

According tothe docs forArgumentsSource:

The source must be within benchmarked type!

It would be nice to lift this restriction. The attribute constructor could have an overload that takes aType parameter.

For example, NUnit'sTestCaseSource does this.

A common pattern in my code is that I have one class which defines all the different cases that a method might encounter. I feed the results of this class into both my unit tests and my benchmarks, to test each case for both correctness and performance. Currently, my benchmark code is bloated with methods that just return immediately with the result of a method in the cases class, which I need to do becauseArgumentsSource can't directly access the method I want to use for the arguments. I would love to be able to remove all those methods.

Example code as it currently is:

[Benchmark][ArgumentsSource(nameof(MethodACases))]publicMethodAResultsBenchmarkMethodA(MethodACase@case)=>CodeBeingBenchmarked.MethodA(@case.Param1,@case.Param2,@case.Param3);publicstaticIEnumerable<MethodACase>MethodACases()=>DiagnosticsCases.MethodACases();

Example code as I propose it ought to be:

[Benchmark][ArgumentsSource(typeof(DiagnosticsCases),nameof(DiagnosticsCases.MethodACases))]publicMethodAResultsBenchmarkMethodA(MethodACase@case)=>CodeBeingBenchmarked.MethodA(@case.Param1,@case.Param2,@case.Param3);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp