Today i saw this bad code structure and since then i started to think its really awkward and horrible to look at this method having this code. The code goes like this:
StringBuilder body = new StringBuilder();
#region General
body.Append("General information:");
body.Append('*');
body.Append('*');
body.Append("Exception: ");
body.Append(m_ExceptionInfo.Exception.GetType().ToString());
body.Append('*');
body.Append("Message: ");
body.Append(m_ExceptionInfo.Exception.Message);
body.Append('*');
body.Append("Method: ");
body.Append(m_ExceptionInfo.GetMethodName(m_ExceptionInfo.Exception));
body.Append('*');
body.Append("Class: ");
body.Append(m_ExceptionInfo.GetClassName(m_ExceptionInfo.Exception));
body.Append('*');
body.Append("Assembly: ");
body.Append(m_ExceptionInfo.AssemblyName);
body.Append('*');
body.Append("App-Domain: ");
body.Append(m_ExceptionInfo.AppDomainName);
body.Append('*');
body.Append("Source-File: ");
body.Append(m_ExceptionInfo.GetFileName(m_ExceptionInfo.Exception));
body.Append('*');
body.Append("Line/Row: ");
body.Append(
m_ExceptionInfo.GetFileLineNumber(m_ExceptionInfo.Exception).ToString(currentNumberFormatInfoProvider));
This we are doing to customize the displayed error message box information in the UI. So for that we are preparing a string having such many information. But to me its feels bad to look at this code and not have any idea how to refactor it.
Any help is appreciated! Thanks
Use StringBuilder.AppendFormat() method: