AssemblyExt.cs 886 B

12345678910111213141516171819202122232425
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. namespace Quadarax.Foundation.Core.Resource.Extensions
  5. {
  6. public static class AssemblyExt
  7. {
  8. public static string GetEmbeddedFileContentAsString(this Assembly owner, string fileName)
  9. {
  10. if (owner==null)
  11. throw new ArgumentNullException(nameof(owner));
  12. if (string.IsNullOrEmpty(fileName))
  13. throw new ArgumentNullException(nameof(fileName));
  14. var resourceName = fileName;
  15. using var fs = owner.GetManifestResourceStream(resourceName);
  16. if (fs == null)
  17. throw new FileNotFoundException($"Cannot find embedded resource file '{resourceName}' is assembly '{owner.GetName().Name}'", resourceName);
  18. using var reader = new StreamReader(fs);
  19. return reader.ReadToEnd();
  20. }
  21. }
  22. }