AssemblyExtensions.cs 754 B

1234567891011121314151617181920212223242526272829
  1. using System.IO;
  2. using System.Reflection;
  3. namespace Abp.Reflection.Extensions
  4. {
  5. public static class AssemblyExtensions
  6. {
  7. /// <summary>
  8. /// Gets directory path of given assembly or returns null if can not find.
  9. /// </summary>
  10. /// <param name="assembly">The assembly.</param>
  11. public static string GetDirectoryPathOrNull(this Assembly assembly)
  12. {
  13. var location = assembly.Location;
  14. if (location == null)
  15. {
  16. return null;
  17. }
  18. var directory = new FileInfo(location).Directory;
  19. if (directory == null)
  20. {
  21. return null;
  22. }
  23. return directory.FullName;
  24. }
  25. }
  26. }