EmbeddedResources

namespace Core.Utility
{
   using System;
   using System.IO;
   using System.Linq;
   using System.Reflection;

   public class EmbeddedResources
   {
      public string GetFile(string filename, string directory, Type currentAssemblyFromType = null)
      {
         var retVal = string.Empty;
         var executingAssembly = Assembly.GetCallingAssembly();
         if (currentAssemblyFromType != null)
         {
            executingAssembly = Assembly.GetAssembly(currentAssemblyFromType);
         }

         var assemblyName = executingAssembly.GetName().FullName.Split(',')[0];

         var path = $"{assemblyName}.{directory}.{filename}";

         var resources = executingAssembly.GetManifestResourceNames().ToList();

         if (!string.IsNullOrWhiteSpace(filename) && resources.Contains(path))
         {
            using (var stream = executingAssembly.GetManifestResourceStream(path))
            {
               if (stream != null)
               {
                  using (var reader = new StreamReader(stream))
                  {
                     retVal = reader.ReadToEnd();
                  }
               }
            }
         }
         else
         {
            throw new FileNotFoundException(filename);
         }

         return retVal;
      }
   }
}