Files
zszq-trs/Framework/YLErp.Core/Helpers/MosPathHelper.cs
T
2024-05-09 14:06:26 +08:00

43 lines
1.3 KiB
C#

namespace YLErp.Core.Helpers
{
/// <summary>
/// 多操作系统文件路径支持
/// </summary>
public static class MosPathHelper
{
/// <summary>
/// Combines two strings into a path.
/// </summary>
/// <param name="path1"> The first path to combine.</param>
/// <param name="path2"> The second path to combine.</param>
/// <returns></returns>
public static string Combine(string path1, string path2)
{
if (!OperatingSystem.IsWindows())
{
path1 = path1?.Replace('\\', '/');
path2 = path2?.Replace('\\', '/');
}
return Path.Combine(path1, path2);
}
/// <summary>
/// Combines an array of strings into a path.
/// </summary>
/// <param name="paths">An array of parts of the path.</param>
/// <returns></returns>
public static string Combine(params string[] paths)
{
if (paths != null && !OperatingSystem.IsWindows())
{
for (var i = 0; i < paths.Length; i++)
{
paths[i] = paths[i]?.Replace('\\', '/');
}
}
return Path.Combine(paths);
}
}
}