Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Running/BenchmarkConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@ private static object Map(object providedValue, Type type)

private static (MemberInfo source, object[] values) GetValidValuesForParamsSource(Type sourceType, string sourceName)
{
var paramsSourceMethod = sourceType.GetAllMethods().SingleOrDefault(method => method.Name == sourceName && method.IsPublic);
var paramsSourceMethod = sourceType.GetAllMethods().FirstOrDefault(method => method.Name == sourceName && method.IsPublic);

if (paramsSourceMethod != default)
return (paramsSourceMethod, ToArray(
paramsSourceMethod.Invoke(paramsSourceMethod.IsStatic ? null : Activator.CreateInstance(sourceType), null),
paramsSourceMethod,
sourceType));

var paramsSourceProperty = sourceType.GetAllProperties().SingleOrDefault(property => property.Name == sourceName && property.GetMethod.IsPublic);
var paramsSourceProperty = sourceType.GetAllProperties().FirstOrDefault(property => property.Name == sourceName && property.GetMethod.IsPublic);

if (paramsSourceProperty != default)
return (paramsSourceProperty, ToArray(
Expand Down
40 changes: 39 additions & 1 deletion tests/BenchmarkDotNet.IntegrationTests/ParamSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace BenchmarkDotNet.IntegrationTests
{
public class ParamSourceTests: BenchmarkTestExecutor
public class ParamSourceTests : BenchmarkTestExecutor
{
public ParamSourceTests(ITestOutputHelper output) : base(output) { }

Expand Down Expand Up @@ -204,5 +204,43 @@ public void SourceWithExplicitCastToTarget_InProcessToolchain_Throws()
// public void SourceWithExplicitCastToTarget_Succeeds(IToolchain toolchain) => CanExecuteWithExtraInfo(typeof(SourceWithExplicitCastToTarget), toolchain);
Assert.ThrowsAny<Exception>(() => CanExecuteWithExtraInfo(typeof(SourceWithExplicitCastToTarget), InProcessEmitToolchain.Instance));
}

public abstract class OverridePropertyBase
{
public abstract int[] GetSourceProperty { get; }

[ParamsSource(nameof(GetSourceProperty))]
public int ParamsTarget { get; set; }
}

public class OverrideProperty : OverridePropertyBase
{
public override int[] GetSourceProperty => new int[] { 1, 2, 3 };

[Benchmark]
public int Benchmark() => ParamsTarget;
}

[Theory, MemberData(nameof(GetToolchains), DisableDiscoveryEnumeration = true)]
public void OverrideProperty_Succeeds(IToolchain toolchain) => CanExecuteWithExtraInfo(typeof(OverrideProperty), toolchain);

public abstract class OverrideMethodBase
{
public abstract int[] GetSourceMethod();

[ParamsSource(nameof(GetSourceMethod))]
public int ParamsTarget { get; set; }
}

public class OverrideMethod : OverrideMethodBase
{
public override int[] GetSourceMethod() => new int[] { 1, 2, 3 };

[Benchmark]
public int Benchmark() => ParamsTarget;
}

[Theory, MemberData(nameof(GetToolchains), DisableDiscoveryEnumeration = true)]
public void OverrideMethod_Succeeds(IToolchain toolchain) => CanExecuteWithExtraInfo(typeof(OverrideMethod), toolchain);
}
}
Loading