-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathProjectSourcePath.cs
More file actions
23 lines (20 loc) · 1.18 KB
/
ProjectSourcePath.cs
File metadata and controls
23 lines (20 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// This is a support file to get the root file directory to resolve a relative path issues with Window vs Linux
// Basically, Windows uses the root file directory so, Redux/Problems, but Linux uses /bin/Debug/net6.0/Problems.
// This makes it so you can always just use the root(Widows on any system)
// E.G: string projectSourcePath = ProjectSourcePath.Value; will return the root path, then you can concatinate where ever you're going after like Problems/...
// Solution is based off StackOverflow (https://stackoverflow.com/a/66285728)
using System.Runtime.CompilerServices;
internal static class ProjectSourcePath
{
private const string myRelativePath = nameof(ProjectSourcePath) + ".cs";
private static string? lazyValue;
public static string Value => lazyValue ??= calculatePath();
private static string calculatePath()
{
string pathName = GetSourceFilePathName();
//Assert( pathName.EndsWith( myRelativePath, StringComparison.Ordinal ) );
return pathName.Substring( 0, pathName.Length - myRelativePath.Length );
}
public static string GetSourceFilePathName( [CallerFilePath] string? callerFilePath = null)
=> callerFilePath ?? "";
}