PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/core/AssemblyHelper.cs

#
C# | 45 lines | 30 code | 9 blank | 6 comment | 2 complexity | b19f5853e1ec5094a64bb3e4468f0755 MD5 | raw file
 1// ****************************************************************
 2// Copyright 2008, Charlie Poole
 3// This is free software licensed under the NUnit license. You may
 4// obtain a copy of the license at http://nunit.org.
 5// ****************************************************************
 6
 7using System;
 8using System.Reflection;
 9
10namespace NUnit.Core
11{
12    public class AssemblyHelper
13    {
14        #region GetAssemblyPath
15
16        public static string GetAssemblyPath(Type type)
17        {
18            return GetAssemblyPath(type.Assembly);
19        }
20
21        public static string GetAssemblyPath(Assembly assembly)
22        {
23            string path = assembly.CodeBase;
24            Uri uri = new Uri(path);
25
26            // If it wasn't loaded locally, use the Location
27            if (!uri.IsFile)
28                return assembly.Location;
29
30            if (uri.IsUnc)
31                return path.Substring(Uri.UriSchemeFile.Length + 1);
32
33            return uri.LocalPath;
34        }
35
36        #endregion
37
38        #region GetDirectoryName
39        public static string GetDirectoryName( Assembly assembly )
40        {
41            return System.IO.Path.GetDirectoryName(GetAssemblyPath(assembly));
42        }
43        #endregion
44    }
45}