PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  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. using System;
  7. using System.Reflection;
  8. namespace NUnit.Core
  9. {
  10. public class AssemblyHelper
  11. {
  12. #region GetAssemblyPath
  13. public static string GetAssemblyPath(Type type)
  14. {
  15. return GetAssemblyPath(type.Assembly);
  16. }
  17. public static string GetAssemblyPath(Assembly assembly)
  18. {
  19. string path = assembly.CodeBase;
  20. Uri uri = new Uri(path);
  21. // If it wasn't loaded locally, use the Location
  22. if (!uri.IsFile)
  23. return assembly.Location;
  24. if (uri.IsUnc)
  25. return path.Substring(Uri.UriSchemeFile.Length + 1);
  26. return uri.LocalPath;
  27. }
  28. #endregion
  29. #region GetDirectoryName
  30. public static string GetDirectoryName( Assembly assembly )
  31. {
  32. return System.IO.Path.GetDirectoryName(GetAssemblyPath(assembly));
  33. }
  34. #endregion
  35. }
  36. }