Closed MovGP0 closed 8 years ago
example code:
public static Science<TResult> Test<TResult>(this Science<TResult> science, Func<TResult> control, Func<TResult> candidate)
{
if(control == null) throw new ArgumentNullException(nameof(control));
if(candidate == null) throw new ArgumentNullException(nameof(candidate));
if(science.Control != null || science.Candidate != null)
{
// message from translatable resource file
var message = ErrorMessages.TestMayNotBeCalledMultipleTimes;
throw new InvalidOperationException(message);
}
science.Control = control;
science.Candidate = candidate;
return science;
}
When
.Test()
is called multiple times, it overrides the Control and Candidate actions.In such cases the user should create a new
Science
using the factory methodShience.New
instead. Therefore, I'd prefer to have to throw anInvalidOperationException()
when.Test()
is called multiple times.