Skip to content

Best way to read files during Benchmark run #2472

Answered by mawosoft
lbussell asked this question in Q&A
Discussion options

You must be logged in to vote

You can use a local helper function like:

static string WhereAmI([CallerFilePath] string callerFilePath = "") => callerFilePath;

and calculate the path relative to the source code file that's calling the function, e.g.

string basePath = Path.GetDirectoryName(WhereAmI());
string targetPath = Path.Combine(basePath, "relative/path/to/file.txt");

For a more complex approach, dealing with deterministic paths, CI, etc. see
https://github.com/mawosoft/MissingCoverage/blob/master/tests/testdata/src/TestDataDirectory.cs

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lbussell
Comment options

Answer selected by lbussell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants