I would like to code a method inside the following:
namespace WebUx.Helpers.CSharp
{
public class getExceptionMessage
{
< Method here >
var exError = e.Message;
if ( e.InnerException != null ) {
exError += "<br>" + e.InnerException.Message;
if (e.InnerException.InnerException != null ) {
exError += "<br>" + e.InnerException.InnerException.Message;
}
}
}
}
Can someone tell me how I should declare the class and method. I get mixed up over how best to declare and I think it should be static but not sure if there is a better way. Note that this method I want to have callable from many places in my code. I think I should probably return a string with the value exError.
In order to avoid those “helper classes” that could be used everywhere in the code I would write an extension method:
then:
I personally don’t really like all those
StringHelper,ExceptionHelper,FormHelper… classes when the only purpose is to provide static methods that are related to a particular type. Extension methods are made for this particular purpose.