0

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.

Ricker
  • 1
  • Proably you are looking for `ResourceManager -> GetResourceSet -> GetEnumerator -> Key` calls (see sample in http://stackoverflow.com/questions/6531677/get-all-strings-from-resourcemanager?rq=1) – Alexei Levenkov Dec 12 '13 at 00:09
  • This is not possible in .NET 2.0 (as far as i know) .With some trickery involving lambda expressions and the *System.Linq.Expressions.Expression* type something similar like this would be possible in .NET3.5 and newer, but not in .NET 2.0. You would likely go for either using string constants (such as `"ErrConnectionCount"`) or some Enum type as keys in your ErrCount dictionary. –  Dec 12 '13 at 00:18
  • Note that string constants as keys are preferred over enums or other key types, since you can use those string keys to query the resource set. –  Dec 12 '13 at 00:29

0 Answers0