// How to use: // Create a function or property for each message text, depending on how many parameters are // part of the message. For the beginning, type plain English text in the function or property. // The use of functions is safe when a parameter must be changed. The compiler tells you all // places in your code that must be modified. // For localization, create an enum value for each function or property with the same name. Then // create localized message files with the enum values as messages identifiers. In the properties // and functions all text is replaced by Format or GetString functions with the corresponding enum value // as first parameter. The use of enums ensures that typing errors in message resource names are // simply impossible. Use the TestResourceMessages function to ensure that each enum value has an // appropriate message text. #region Helper functions /// <summary> /// Loads the message from the resource associated with the enum type and formats it /// using 'String.Format'. Because this function is intended to be used during error /// handling it never raises an exception. /// </summary> /// <param name="id">The type of the parameter identifies the resource /// and the name of the enum identifies the message in the resource.</param> /// <param name="args">Parameters passed through 'String.Format'.</param> /// <returns>The formatted message.</returns> public static string Format(PSMsgID id, params object[] args) { string message; try { message = PSSR.GetString(id); message = message != null ? Format(message, args) : "INTERNAL ERROR: Message not found in resources."; return message; } catch (Exception ex) { message = String.Format("UNEXPECTED ERROR while formatting message with ID {0}: {1}", id.ToString(), ex.ToString()); } return message; }
// How to use: // Create a function or property for each message text, depending on how many parameters are // part of the message. For the beginning, type plain English text in the function or property. // The use of functions is safe when a parameter must be changed. The compiler tells you all // places in your code that must be modified. // For localization, create an enum value for each function or property with the same name. Then // create localized message files with the enum values as messages identifiers. In the properties // and functions all text is replaced by Format or GetString functions with the corresponding enum value // as first parameter. The use of enums ensures that typing errors in message resource names are // simply impossible. Use the TestResourceMessages function to ensure that each enum value has an // appropriate message text. #region Helper functions /// <summary> /// Loads the message from the resource associated with the enum type and formats it /// using 'String.Format'. Because this function is intended to be used during error /// handling it never raises an exception. /// </summary> /// <param name="id">The type of the parameter identifies the resource /// and the name of the enum identifies the message in the resource.</param> /// <param name="args">Parameters passed through 'String.Format'.</param> /// <returns>The formatted message.</returns> public static string Format(PSMsgID id, params object[] args) { string message; try { message = GetString(id); message = message != null?Format(message, args) : "INTERNAL ERROR: Message not found in resources."; return(message); } catch (Exception ex) { message = String.Format("UNEXPECTED ERROR while formatting message with ID {0}: {1}", id.ToString(), ex.ToString()); } return(message); }
//// /// <summary> //// /// Loads the message from the resource associated with the enum type and formats it //// /// using 'String.Format'. Because this function is intended to be used during error //// /// handling it never raises an exception. //// /// </summary> //// /// <param name="id">The type of the parameter identifies the resource //// /// and the name of the enum identifies the message in the resource.</param> //// /// <param name="args">Parameters passed through 'String.Format'.</param> //// /// <returns>The formatted message.</returns> public static string Format(PSMsgID id, params object[] args) { string message; try { message = PSSR.GetString(id); if (message != null) message = Format(message, args); else message = "INTERNAL ERROR: Message not found in resources."; return message; } catch (Exception ex) { message = "UNEXPECTED ERROR while formatting message: " + ex.ToString(); } return message; }
/// <summary> /// Gets the localized message identified by the specified DomMsgID. /// </summary> public static string GetString(PSMsgID id) { return(ResMngr.GetString(id.ToString())); }
/// <summary> /// Gets the localized message identified by the specified DomMsgID. /// </summary> public static string GetString(PSMsgID id) { return PSSR.ResMngr.GetString(id.ToString()); }
/// <summary> /// Gets the localized message identified by the specified DomMsgID. /// </summary> public static string GetString(PSMsgID id) => ResMngr.GetString(id.ToString());