61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using System.Text;
|
|
|
|
namespace CommonLibrary
|
|
{
|
|
public static class Extensions
|
|
{
|
|
public static string PathCombineL(params string[] paths)
|
|
{
|
|
string directorySeparatorChar = System.IO.Path.AltDirectorySeparatorChar.ToString();
|
|
return PathCombine(directorySeparatorChar, paths).Replace("\\", "/");
|
|
}
|
|
|
|
public static string PathCombineW(params string[] paths)
|
|
{
|
|
string directorySeparatorChar = System.IO.Path.DirectorySeparatorChar.ToString();
|
|
return PathCombine(directorySeparatorChar, paths).Replace("/", "\\");
|
|
}
|
|
|
|
private static string PathCombine(string directorySeparator, params string[] paths)
|
|
{
|
|
if (paths.Length == 0)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
StringBuilder path = new StringBuilder();
|
|
path.Append(paths[0]);
|
|
for (int i = 1; i < paths.Length; i++)
|
|
{
|
|
if (path.ToString().Substring(path.Length - 1, 1) == directorySeparator)
|
|
{
|
|
if (paths[i].Substring(0, 1) == directorySeparator)
|
|
{
|
|
path.Append(paths[i].Substring(1, paths[i].Length - 1));
|
|
}
|
|
else
|
|
{
|
|
path.Append(paths[i]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (paths[i].Substring(0, 1) == directorySeparator)
|
|
{
|
|
path.Append(paths[i]);
|
|
}
|
|
else
|
|
{
|
|
path.Append(directorySeparator);
|
|
path.Append(paths[i]);
|
|
}
|
|
}
|
|
}
|
|
return path.ToString();
|
|
}
|
|
public static bool IsDefault<T>(ref this T data) where T : struct
|
|
{
|
|
return default(T).Equals(data);
|
|
}
|
|
}
|
|
} |