-
Notifications
You must be signed in to change notification settings - Fork 0
/
AssemblyExtensions.cs
31 lines (27 loc) 路 1.06 KB
/
AssemblyExtensions.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
锘縰sing System;
using System.IO;
using System.Reflection;
namespace Songhay.Extensions
{
/// <summary>Extensions of <see cref="Assembly"/>.</summary>
public static class AssemblyExtensions
{
/// <summary>Gets the path from assembly.</summary>
/// <param name="assembly">The assembly.</param>
/// <exception cref="ArgumentNullException">assembly - The expected assembly is not here.</exception>
public static string GetPathFromAssembly(this Assembly assembly)
{
if (assembly == null) throw new ArgumentNullException(nameof(assembly), "The expected assembly is not here.");
var hasCodeBaseOnWindows =
!string.IsNullOrEmpty(assembly.CodeBase)
&&
!FrameworkFileUtility.IsForwardSlashSystem()
;
var location = hasCodeBaseOnWindows ?
assembly.CodeBase.Replace("file:///", string.Empty) :
assembly.Location;
var root = Path.GetDirectoryName(location);
return root;
}
}
}