I have an enum for which I use a custom Description attribute to bind it to resource strings. Is there a way I can use expressions like LanguageStrings.STR_RELEASED than constant strings like STR_RELEASED in description? This doesn't look maintainable to me. I want a compiler error if a resource string is modified in files but not in enum descriptor ? Here is my sample code.
public enum VaccumStatus
{
[LocalizedDescription("STR_RELEASED")]
Released,
[LocalizedDescription("SHUT_DOWN_SYSTEM")]
ShutDown,
[LocalizedDescription("VAC_MAINTAINED")]
Maintained,
}
public class LocalizedDescriptionAttribute : DescriptionAttribute
{
readonly string _resourceKey;
public LocalizedDescriptionAttribute(string resourceKey)
{
_resourceKey = resourceKey;
}
public override string Description
{
get
{
string description = LanguageStrings.ResourceManager.GetString(_resourceKey);
return string.IsNullOrWhiteSpace(description) ? $"[[{_resourceKey}]]" : description;
}
}
}