using System.IO; using System.Reflection; using System.Text; using Serilog; namespace TINK.ViewModel { public static class ViewModelResourceHelper { /// Get ressource prefix depending on platform. public static string RessourcePrefix { get { #if __IOS__ return "TINK.iOS."; #endif #if __ANDROID__ return "TINK.Droid."; #endif #if WINDOWS_UWP return "TINK.WinPhone."; #endif } } /// Gets an an embedded html ressource. /// Name of resource to get. /// public static string GetEmbeddedResource(string resrouceName) { var ressourceName = RessourcePrefix + resrouceName; Log.Verbose($"Using this resource prefix {RessourcePrefix}."); // note that the prefix includes the trailing period '.' that is required var assembly = typeof(ViewModelResourceHelper).GetTypeInfo().Assembly; var stream = assembly.GetManifestResourceStream(ressourceName); return stream != null ? (new StreamReader(stream, Encoding.UTF8)).ReadToEnd() : string.Format("An error occurred loading html- ressource {0}.", ressourceName); } } }