title: Automagically handling multi-lingual properties in a .NET class
body: <p>I am trying to handle multiple languages in an ASP.NET Webforms (.NET 4.5, C#) application of mine.</p>
  
  <p>Basically, some of my entities in my SQL Server 2012 database have properties like <code>Name</code> or <code>Description</code> which exist in three languages - German, French, Italian.</p>
  
  <p>Those are stored as columns <code>Name_De</code> (German), <code>Name_Fr</code> (French), and <code>Name_It</code> (Italian).</p>
  
  <p>When I create my .NET objects from the database, of course, I also get those three properties in my entity class. But for displaying on screen, in a grid for instance, it would be nice if I could somehow "magically" always show the "right" language. This should be based on the <code>Thread.Current.CurrentUICulture.TwoLetterISOLanguageName</code> (which returns <code>de</code>, <code>fr</code> or <code>it</code>, depending on the browser's language preferences).</p>
  
  <p>So I was hoping to somehow be able to create e.g. a .NET attribute that would allow me to do something like this:</p>
  
  <p>Base "Module" entity - generated from existing SQL Server database:</p>
  
  <pre><code>public partial class Module
  {
      public string ModuleCode { get; set; }
  
      public string Name_De { get; set; }
      public string Name_Fr { get; set; }
      public string Name_It { get; set; }
  
      ... // other properties
  }
  </code></pre>
  
  <p>Partial extension in a separate file</p>
  
  <pre><code>public partial class Module
  {
      [Multilingual]
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>The base idea is: I can access the <code>Module.Name</code> property, and depending on the current setting of <code>CurrentUICulture</code>, either the value of <code>Name_De</code>, <code>Name_Fr</code> or <code>Name_It</code> would be fetched, when I access the getter of the <code>Name</code> property.</p>
  
  <p>Can something like this be done in C# ? I have looked at a lot of custom attribute implementations, but nothing ever seemed to be doing something like this...</p>