c# - Best way of mapping external error codes to internal codes -
what mean if error code 300 service, , need map our own internal error code (say 450), whats best way of doing this.
current system uses constants keep track of internal errors:
public const string error_some = "450"; public const string error_another = "460";...
so thinking of having set of constants external errors , have function mapping two:
public const string ext_error_some = "300"; public const string ext_error_another = "800"; ... public string maperror(string externalerror) { if(externalerror == ext_error_some) // can switch statement return error_some; else if (externalerror == ext_error_another) return error_another; ... }
the question is: "is there better way"?
you can use dictionary<string, string>
:
private readonly var errormap = new dictionary<string, string>() { {ext_error_some, error_some}, ⋮ }; public string maperror(string externalerror) { return errormap[externalerror]; }
Comments
Post a Comment