.Net 2.0 get name of resource string from ResourceManager

237 views Asked by At

What problem am I trying to solve? Pseudo-code using C#

I have a list of error messages as resource string. The message may take parameters.

Key                  Value
ErrConnectionCount   "Connections exceeded by {0}. Contact your network administrator"
ErrIncorrectValue    "Input data was {0}. Expected {1}"

A dictionary exists that tracks the number of times an error occurred.

Dictionary<string,int> ErrCount;
...
if (error_condition)
    ErrCount[MyResManager.ErrConnectionCount.Name] += 1;

In the example, I specified a property called "Name" to illustrate what I would like to do. In fact, there is no such property.

Hopefully, you can see that it is better to key the dictionary by the "name" of the resource instead of the language-specific value. At another place in the program the Dictionary of errors could report the error codes and how many times they occurred.

Is there a way to do this in .Net 2.0? Thank you.

0

There are 0 answers