EmbeddedResourceItem.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using JetBrains.Annotations;
  5. namespace Abp.Resources.Embedded
  6. {
  7. /// <summary>
  8. /// Stores needed information of an embedded resource.
  9. /// </summary>
  10. public class EmbeddedResourceItem
  11. {
  12. /// <summary>
  13. /// File name including extension.
  14. /// </summary>
  15. public string FileName { get; }
  16. [CanBeNull]
  17. public string FileExtension { get; }
  18. /// <summary>
  19. /// Content of the resource file.
  20. /// </summary>
  21. public byte[] Content { get; set; }
  22. /// <summary>
  23. /// The assembly that contains the resource.
  24. /// </summary>
  25. public Assembly Assembly { get; set; }
  26. public DateTime LastModifiedUtc { get; }
  27. internal EmbeddedResourceItem(string fileName, byte[] content, Assembly assembly)
  28. {
  29. FileName = fileName;
  30. Content = content;
  31. Assembly = assembly;
  32. FileExtension = CalculateFileExtension(FileName);
  33. LastModifiedUtc = Assembly.Location != null
  34. ? new FileInfo(Assembly.Location).LastWriteTimeUtc
  35. : DateTime.UtcNow;
  36. }
  37. private static string CalculateFileExtension(string fileName)
  38. {
  39. if (!fileName.Contains("."))
  40. {
  41. return null;
  42. }
  43. return fileName.Substring(fileName.LastIndexOf(".", StringComparison.Ordinal) + 1);
  44. }
  45. }
  46. }