// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) James South. // Licensed under the Apache License, Version 2.0. // // // Provides helper methods for working with resources. // // -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor.Web.Helpers { using System.IO; using System.Reflection; using System.Text; /// /// Provides helper methods for working with resources. /// public class ResourceHelpers { /// /// Converts an assembly resource into a string. /// /// /// The resource. /// /// /// The assembly. /// /// /// The character encoding to return the resource in. /// /// /// The . /// public static string ResourceAsString(string resource, Assembly assembly = null, Encoding encoding = null) { assembly = assembly ?? Assembly.GetExecutingAssembly(); encoding = encoding ?? Encoding.UTF8; using (MemoryStream ms = new MemoryStream()) { using (Stream manifestResourceStream = assembly.GetManifestResourceStream(resource)) { if (manifestResourceStream != null) { manifestResourceStream.CopyTo(ms); } } return encoding.GetString(ms.GetBuffer()).Replace('\0', ' ').Trim(); } } } }