-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPathExtensions.cs
38 lines (34 loc) · 1.05 KB
/
PathExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.IO;
using System.Linq;
namespace ChpokkWeb.Infrastructure {
public static class PathExtensions {
[NotNull]
public static string AppendPathEvenIfItIsRooted(this string path, [NotNull] params string[] appended) {
foreach (var next in appended) {
var toAppend = next;
if (Path.IsPathRooted(next)) {
toAppend = next.Substring(Path.GetPathRoot(next).Length);
}
path = Path.Combine(path, toAppend?? string.Empty);
}
return path;
}
/// <summary>
/// Gets filename from either url or physicl path
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[NotNull]
public static string GetFileNameUniversal([NotNull] this string path) {
var parts = path.Split('/', '\\');
return parts.Last();
}
[NotNull]
public static string RemoveExtension([NotNull] this string name) {
return Path.GetFileNameWithoutExtension(name);
}
public static string RemoveFromStart(this string path, string root) {
return path.Substring(root.Length);
}
}
}