Is there a way in C# to have the compiler enforce that users use
Resource Strings?
Say I have a logging subsystem, and I want make sure that the only
string values that get logged come from a resource file, can I do
that?
I know I can use:
static void LogWarning(string val)
{
...
string toLog = ResourceManager.GetString(val);
}
But that is problematic: At compile time, I have no idea if val
exists.
I can also use:
static void LogWarning(string msg)
{
....
}
LogWarning(ErrorStrings.ThisIsMyError);
But nothing stops users of this log system from passing in a hardcoded
string into my LogWarning method.
Ideally I want something that is strongly typed, but can't be
overloaded with a string.
Any ideas?