/src/NUnit/core/AssemblyHelper.cs
C# | 45 lines | 30 code | 9 blank | 6 comment | 2 complexity | b19f5853e1ec5094a64bb3e4468f0755 MD5 | raw file
Possible License(s): GPL-2.0
- // ****************************************************************
- // Copyright 2008, Charlie Poole
- // This is free software licensed under the NUnit license. You may
- // obtain a copy of the license at http://nunit.org.
- // ****************************************************************
-
- using System;
- using System.Reflection;
-
- namespace NUnit.Core
- {
- public class AssemblyHelper
- {
- #region GetAssemblyPath
-
- public static string GetAssemblyPath(Type type)
- {
- return GetAssemblyPath(type.Assembly);
- }
-
- public static string GetAssemblyPath(Assembly assembly)
- {
- string path = assembly.CodeBase;
- Uri uri = new Uri(path);
-
- // If it wasn't loaded locally, use the Location
- if (!uri.IsFile)
- return assembly.Location;
-
- if (uri.IsUnc)
- return path.Substring(Uri.UriSchemeFile.Length + 1);
-
- return uri.LocalPath;
- }
-
- #endregion
-
- #region GetDirectoryName
- public static string GetDirectoryName( Assembly assembly )
- {
- return System.IO.Path.GetDirectoryName(GetAssemblyPath(assembly));
- }
- #endregion
- }
- }