After .NET 5, System.IO.Path
was made to be cross platform. I'd expect this to work everywhere.
private static bool IsSubPath(string parent, string child)
{
string relPath = Path.GetRelativePath(parent, child);
return !(Path.IsPathRooted(relPath) || relPath.StartsWith(".."));
}