-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathFileHelper.cs
44 lines (39 loc) · 1.28 KB
/
FileHelper.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
39
40
41
42
43
44
using System;
using System.IO;
namespace KellermanSoftware.CompareNetObjects
{
/// <summary>
/// Helper methods for files and directories
/// </summary>
public static class FileHelper
{
/// <summary>
/// Get the current directory of the executing assembly
/// </summary>
/// <returns></returns>
public static string GetCurrentDirectory()
{
#if NETSTANDARD
string basePath = AppContext.BaseDirectory;
#else
string basePath = AppDomain.CurrentDomain.BaseDirectory;
#endif
return PathSlash(basePath);
}
/// <summary>
/// Ensure the passed string ends with a directory separator character unless the string is blank.
/// </summary>
/// <param name="path">The string to append the backslash to.</param>
/// <returns>String with a "/" on the end</returns>
public static String PathSlash(string path)
{
string separator = Convert.ToString(Path.DirectorySeparatorChar);
if (path.Length == 0)
return path;
else if (path.EndsWith(separator))
return path;
else
return path + separator;
}
}
}