title: How can I internationalize strings representing C# enum values?
body: <p>I've seen many questions and answers about mapping strings to enums and vice-versa, but how can I map a series of localized strings to enums?</p>
  
  <p>Should I just create an <a href="https://stackoverflow.com/questions/479410/enum-tostring/479453#479453">extension method like this</a> that returns the proper string from a resource file?  Is there a way to localize attributes (like "Description") that are used in <a href="https://stackoverflow.com/questions/479410/enum-tostring/479417#479417">solutions like this</a>?</p>
  
  <p>Which is the preferred solution - extension method or attributes.  It seems to me that this isn't the intended purpose of attributes.  In fact, now that I think about it, if I were to use an extension method an attribute seems like something I'd use to specify a key in a resource file for the localized string I want to use in place of the enum value.</p>
  
  <p>EDIT - example:</p>
  
  <p>Given the following enum,</p>
  
  <pre><code>public enum TransactionTypes {
      Cheque = 1,
      BankTransfer = 2,
      CreditCard = 3
  }
  </code></pre>
  
  <p>I would like a way to map each type to a localized string.  I started off with an extension method for the enum that uses a switch statement and strongly typed references to the resource file.</p>
  
  <p>However, an extension method for every enum doesn't seem like a great solution.  I've started following <a href="https://stackoverflow.com/questions/424366/c-string-enums">this</a> to create a custom attribute for each enumerated value.  The attribute has a base name and key for the resource file containing localized strings.  In the above enum, for example, I have this:</p>
  
  <pre><code>...
  [EnumResourceAttribute("FinancialTransaction", "Cheque")]
  Cheque = 1,
  ...
  </code></pre>
  
  <p>Where "FinanacialTransaction" is the resx file and "Cheque" is the string key.  I'm trying to create a utility method to which I could pass any value from any enumeration and have it return the localized string representation of that value, assuming the custom attribute is specified.  I just can't figure out how to dynamically access a resource file and a key within it.</p>