AssemblyHelper
AssemblyHelper provides static methods for working
with assemblies.
using System.IO;
using System.Reflection;
namespace NUnit.Framework.Internal
{
public static class AssemblyHelper
{
private const string UriSchemeFile = "file";
private const string SchemeDelimiter = "://";
public static string GetAssemblyPath(Assembly assembly)
{
string codeBase = assembly.CodeBase;
if (IsFileUri(codeBase))
return GetAssemblyPathFromCodeBase(codeBase);
return assembly.Location;
}
public static string GetDirectoryName(Assembly assembly)
{
return Path.GetDirectoryName(GetAssemblyPath(assembly));
}
public static AssemblyName GetAssemblyName(Assembly assembly)
{
return assembly.GetName();
}
public static Assembly Load(string nameOrPath)
{
string a = Path.GetExtension(nameOrPath).ToLower();
if (a == ".dll" || a == ".exe")
return new AssemblyLoader().LoadFromAssemblyPath(Path.GetFullPath(nameOrPath));
return Assembly.Load(new AssemblyName {
Name = nameOrPath
});
}
private static bool IsFileUri(string uri)
{
return uri.ToLower().StartsWith("file");
}
public static string GetAssemblyPathFromCodeBase(string codeBase)
{
int num = "file".Length + "://".Length;
if (codeBase[num] == '/') {
if (codeBase[num + 2] == ':')
num++;
} else if (codeBase[num + 1] != ':') {
num -= 2;
}
return codeBase.Substring(num);
}
}
}