using System.Linq;
using System.Windows.Media.Imaging;

namespace Editor
{
    public static class BitmapLoader<T>
    {
        public static BitmapSource Load(string s)
        {
            var assembly = typeof(T).Assembly;
            var resNames = assembly.GetManifestResourceNames();
            var resName = s.Replace("\\", ".");
            resName = resNames.First(r => r.Contains(resName));
            var bitmap = new BitmapImage();
            using (var stream = assembly.GetManifestResourceStream(resName))
            {
                bitmap.BeginInit();
                bitmap.StreamSource = stream;
                bitmap.CacheOption = BitmapCacheOption.OnLoad;
                bitmap.EndInit();
            }
            return bitmap;
        }
    }
}