using System; using System.Reflection; using System.Resources; using System.Text; namespace HakInstaller.Utilities { /// /// This class is used to manipulate the assembly's string resources. /// public class StringResources { #region public static properties/methods /// /// Gets the specified string from the string resource file. /// /// The name of the string to load /// The string value public static string GetString(string name) { return singleton.rm.GetString(name); } /// /// Gets the specified format string from the string resource file, formatting /// it with the passed string arguments. /// /// The name of the format string to load /// The string format arguments /// The formatted string value public static string GetString(string name, params object[] args) { // Get the format string from the resource file and // format it with the passed arguments. string format = singleton.rm.GetString(name); singleton.builder.Length = 0; singleton.builder.AppendFormat(format, args); return singleton.builder.ToString(); } #endregion #region private fields/properties/methods /// /// Class constructor made private because class is a singleton. /// private StringResources() { builder = new StringBuilder(); rm = new ResourceManager("HakInstaller.strings", Assembly.GetExecutingAssembly()); } private static StringResources singleton = new StringResources(); private StringBuilder builder; private ResourceManager rm; #endregion } }