/// <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 FormatMessage(DomMsgID id, params object[] args) { string message; try { message = DomSR.GetString(id); if (message != null) { #if DEBUG if (Regex.Matches(message, @"\{[0-9]\}").Count > args.Length) { //TODO too many placeholders or too less args... } #endif message = String.Format(message, args); } else message = "<<<error: message not found>>>"; return message; } catch (Exception ex) { message = "INTERNAL ERROR while formatting error message: " + ex.ToString(); } return message; }
internal static string FormatMessage(DomMsgID id, params object[] args) { string message; try { message = GetString(id); if (message != null) { #if DEBUG if (Regex.Matches(message, @"\{[0-9]\}").Count > args.Length) { //TODO too many placeholders or too less args... } #endif message = String.Format(message, args); } else { message = "<<<error: message not found>>>"; } return(message); } catch (Exception ex) { message = "INTERNAL ERROR while formatting error message: " + ex.ToString(); } return(message); }
internal static string GetString(DomMsgID id) { return((string)typeof(AppResources).GetProperties().Where(x => x.Name == id.ToString() && x.PropertyType == typeof(string)).FirstOrDefault()?.GetValue(null)); }
/// <summary> /// Initializes a new instance of the DdlParserException class with the specified error level, name, /// error code and message. /// </summary> public DdlParserException(DdlErrorLevel level, string message, DomMsgID errorCode) : base(message) { _error = new DdlReaderError(level, message, (int)errorCode); }
/// <summary> /// Gets the localized message identified by the specified DomMsgID. /// </summary> public static string GetString(DomMsgID id) { return DomSR.ResMngr.GetString(id.ToString()); }
/// <summary> /// Determines the error message based on the DomMsgID and the parameters. /// Throws a DdlParserException with that error message and the Exception as the inner exception. /// </summary> private void ThrowParserException(Exception innerException, DomMsgID errorCode, params object[] parms) { string message = DomSR.FormatMessage(errorCode, parms); throw new DdlParserException(message, innerException); }
/// <summary> /// Creates an ErrorInfo based on the DomMsgID and the specified parameters. /// Throws a DdlParserException with that ErrorInfo. /// </summary> private void ThrowParserException(DomMsgID errorCode, params object[] parms) { string message = DomSR.FormatMessage(errorCode, parms); DdlReaderError error = new DdlReaderError(DdlErrorLevel.Error, message, (int)errorCode, _scanner.DocumentFileName, _scanner.CurrentLine, _scanner.CurrentLinePos); throw new DdlParserException(error); }
/// <summary> /// Creates an ErrorInfo based on the given inner exception, error and parms and adds it to the ErrorManager2. /// </summary> private void ReportParserException(Exception innerException, DomMsgID errorCode, params string[] parms) { string message = ""; if (innerException != null) message = ": " + innerException; message += DomSR.FormatMessage(errorCode, parms); DdlReaderError error = new DdlReaderError(DdlErrorLevel.Error, message, (int)errorCode, _scanner.DocumentFileName, _scanner.CurrentLine, _scanner.CurrentLinePos); _errors.AddError(error); }
/// <summary> /// Creates an ErrorInfo based on the given error and parms and adds it to the ErrorManager2. /// </summary> private void ReportParserException(DomMsgID error, params string[] parms) { ReportParserException(null, error, parms); }
/// <summary> /// Creates an ErrorInfo based on the given errorlevel, error and parms and adds it to the ErrorManager2. /// </summary> private void ReportParserInfo(DdlErrorLevel level, DomMsgID errorCode, params string[] parms) { string message = DomSR.FormatMessage(errorCode, parms); DdlReaderError error = new DdlReaderError(level, message, (int)errorCode, _scanner.DocumentFileName, _scanner.CurrentLine, _scanner.CurrentLinePos); _errors.AddError(error); }
/// <summary> /// If current symbol is not equal symbol a DdlParserException with the specified message id /// will be thrown. /// </summary> private void AssertSymbol(Symbol symbol, DomMsgID err, params object[] parms) { if (Symbol != symbol) ThrowParserException(err, KeyWords.NameFromSymbol(symbol), parms); }
/// <summary> /// If current symbol is not equal symbol a DdlParserException with the specified message id /// will be thrown. /// </summary> private void AssertSymbol(Symbol symbol, DomMsgID err) { if (Symbol != symbol) ThrowParserException(err, KeyWords.NameFromSymbol(symbol), Token); }
/// <summary> /// If cond is evaluated to false, a DdlParserException with the specified error will be thrown. /// </summary> private void AssertCondition(bool cond, DomMsgID error, params object[] args) { if (!cond) ThrowParserException(error, args); }
/// <summary> /// Gets the localized message identified by the specified DomMsgID. /// </summary> public static string GetString(DomMsgID id) { return(ResMngr.GetString(id.ToString())); }
/// <summary> /// Initializes a new instance of the DdlParserException class with the specified error level, name, /// error code and message. /// </summary> public DdlParserException(DdlErrorLevel level, string message, DomMsgID errorCode) : base(message) { this.error = new DdlReaderError(level, message, (int)errorCode); }