2022-03-15 16:59:24 +00:00
|
|
|
|
namespace ASC.Common.Utils;
|
2022-02-03 15:26:44 +00:00
|
|
|
|
|
|
|
|
|
public static class CrossPlatform
|
2021-04-16 13:26:26 +00:00
|
|
|
|
{
|
2022-02-10 12:14:50 +00:00
|
|
|
|
private static char[] _pathSplitCharacters = new char[] { '/', '\\' };
|
2022-02-03 15:26:44 +00:00
|
|
|
|
|
|
|
|
|
public static string PathCombine(string basePath, params string[] additional)
|
2021-04-16 13:26:26 +00:00
|
|
|
|
{
|
2022-02-10 12:14:50 +00:00
|
|
|
|
var splits = additional.Select(s => s.Split(_pathSplitCharacters)).ToArray();
|
2022-02-03 15:26:44 +00:00
|
|
|
|
var totalLength = splits.Sum(arr => arr.Length);
|
|
|
|
|
var segments = new string[totalLength + 1];
|
|
|
|
|
segments[0] = basePath;
|
|
|
|
|
var i = 0;
|
2022-02-03 14:18:58 +00:00
|
|
|
|
|
2022-02-03 15:26:44 +00:00
|
|
|
|
foreach (var split in splits)
|
2021-04-16 13:26:26 +00:00
|
|
|
|
{
|
2022-02-03 15:26:44 +00:00
|
|
|
|
foreach (var value in split)
|
2021-04-16 13:26:26 +00:00
|
|
|
|
{
|
2022-02-03 15:26:44 +00:00
|
|
|
|
i++;
|
|
|
|
|
segments[i] = value;
|
2021-04-16 13:26:26 +00:00
|
|
|
|
}
|
2022-02-03 15:26:44 +00:00
|
|
|
|
}
|
2022-02-01 14:51:29 +00:00
|
|
|
|
|
2022-02-03 15:26:44 +00:00
|
|
|
|
return Path.Combine(segments);
|
2021-04-16 13:26:26 +00:00
|
|
|
|
}
|
2022-02-03 15:26:44 +00:00
|
|
|
|
}
|