Solved

C# Error message formatting

Posted on 2014-09-11
3
47 Views
Last Modified: 2016-06-21
we currently have a very convoluted methodology for displaying error messages.  But right now, I would just like to know how to correct one specific message.
The code used to build the message is:
        /// <summary>
        /// Adds the error details.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="errors">The errors.</param>
        private void AddErrorDetails(ref string message, Dictionary<string, string> errors)
        {
            if (errors == null)
            {
                return;
            }

            if (message == null)
            {
                message = string.Empty;
            }

            foreach (string key in errors.Keys)
            {
                if (!string.IsNullOrEmpty(message))
                {
                    message += Environment.NewLine;
                }

                if (key != null)
                {
                    message += errors[key];
                }
            }
        }

Open in new window


the resulting message looks like:

error-msg.png
I would like it to be more like:

Delivery succeeded but with errors. See below for details.
Adjusting stock:  NrfiInd=N, ParentMals UIC = 09107,  Niin = 007345641, Location - Staging......

you get the idea.
Any help would be appreciated.
0
Comment
Question by:PSCTECH
3 Comments
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 40318551
Just to clarify, your question is about:
a) How to remove the curly braces regardless of their location?
b) How to remove extra key entry? e.g.  ParentMals={ParentMals UIC = 09107} to  ParentMals UIC = 09107
c) Are the extra keys well known values? (e.g. we can create a list so that we can replace them accordingly)

For (a), you just need to replace the braces with a blank space as follows:
message.Replace("{", " ").Replace("}", " ");

Open in new window



If more help is needed please post errors[key] contents and answer to my questions.
0
 

Author Comment

by:PSCTECH
ID: 40319082
a. worked great, thank you.
b. yes that's how I want it to display
c.  no they are volatile and set at run time

I'm not at the office right now, I will try to get the errors[key] content as soon as I can
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question