-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
26 lines (23 loc) · 1.02 KB
/
Utils.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
using System.IO;
using System.Reflection;
namespace UnityModStudio.Common
{
public static class Utils
{
private static readonly string DirectorySeparator = Path.DirectorySeparatorChar.ToString();
/// <summary>
/// Get NuGet package version of a Unity Mod Studio assembly.
/// </summary>
/// <param name="assembly">An assembly to inspect.</param>
/// <returns>Version string or <c>null</c> if none is defined.</returns>
public static string? GetPackageVersion(Assembly assembly) =>
assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion.Split('+')[0];
/// <summary>
/// Appends trailing slash to a path if missing.
/// </summary>
/// <param name="path">Input path.</param>
/// <returns>Path ending with trailing slash.</returns>
public static string AppendTrailingSlash(string path) =>
path.EndsWith(DirectorySeparator) ? path : path + DirectorySeparator;
}
}