scientistproject / Scientist.net

A .NET library for carefully refactoring critical paths. It's a port of GitHub's Ruby Scientist library
MIT License
1.46k stars 95 forks source link

[Question] How to test out/ref parameters #90

Closed danielepo closed 7 years ago

danielepo commented 7 years ago

Is there an advised way to verify the status of out parameters?

joncloud commented 7 years ago

Currently Scientist only has support for inspecting a return value. I came up with a way that could be used to inspect out parameters. Basically it wraps up all outputs (returns, outs, refs) into one return result, however this may be more cumbersome to use.

IntTryParseResult ParseInt(string s) {
  return Scientist.Science<IntTryParseResult>(nameof(ParseInt), experiment => {
    experiment.Use(() => {
      int value;
      bool success = int.TryParse(s, out value);
      return new IntTryParseResult(value, success);
    });
  });
}

class IntTryParseResult {
  public IntTryParseResult(int value, bool success);
  public bool Success { get; }
  public int Value { get; }
}