Hi all, I'm creating an application that I would like to Localize down the road and so I've put every string in a Resources.resx file. I'm struggling to find an elegant solution to getting error message strings. As of right now, I pass an enum around to reference which error has occurred, then use that enum to lookup the strings I need just before displaying.
With everything in the .resx file, the problem is that we don't know the error until it occurs, so I need a way to dynamically locate the correct strings rather than hardcode them. I could use a switch statement with the enum as the arg, but this feels sloppy. Here's an example:
switch(errorCode)
{
case error1:
error.errorName = Resources.Error1_NoDevicesName;
error.errorDesc = Resources.Error1_NoDevicesDescription;
break;
case error2:
error.errorName = Resources.Error2_DeviceConnectionName;
error.errorDesc = Resources.Error2_DeviceConnectionDescription;
break;
}
However, I'm wondering if it would be possible to search by a partial name instead, where we look for a name that starts with "Error" + "errorCode.ToString()" and ends with "Name"? Or perhaps there's a better way to do this?
EDIT: No clue what is going on with the formatting