W
Wavemaker
I'm writing a class whose methods can throw exceptions under certain
circumstances. These exceptions will need string messages. I was
thinking about placing these messages in a resource instead of hard
coding them into the class itself.
The question I'm pondering is where would be the best place to load
these string resources? The string messages will be the same for
every instance of the class, so I was thinking about loading the
resource in a static constructor, retrieving the messages, and
storing them in class fields. This prevents the resources from being
repeatedly loaded each time a new instance of the class is
instantiated.
Are there any disadvantages to this approach? The only problem I can
think of is dealing with a situation in which the culture is changed
at some point during runtime. The resources would need to be
reloaded at that point. Admittedly, at this point, I am only
supporting one culture, so this may not be an issue, but this could
change in the future.
circumstances. These exceptions will need string messages. I was
thinking about placing these messages in a resource instead of hard
coding them into the class itself.
The question I'm pondering is where would be the best place to load
these string resources? The string messages will be the same for
every instance of the class, so I was thinking about loading the
resource in a static constructor, retrieving the messages, and
storing them in class fields. This prevents the resources from being
repeatedly loaded each time a new instance of the class is
instantiated.
Are there any disadvantages to this approach? The only problem I can
think of is dealing with a situation in which the culture is changed
at some point during runtime. The resources would need to be
reloaded at that point. Admittedly, at this point, I am only
supporting one culture, so this may not be an issue, but this could
change in the future.