Are custom attributes for Enums dangerous? <p>I am building an application that makes heavy use of <code>Enum</code>s for custom data. Essentially, an object is stored in the database with about 28 separate attributes. Each attribute is a two-character field that's translated from the SQL straight over to an <code>Enum</code>.</p> <p>Unfortunately, I need to also translate these values into two different human-readable values. One for a legend on a data table, and one for a CSS class to style an image on the web application front-end.</p> <p>To do this, I've set up two custom attributes and applied them to the <code>Enum</code> where necessary. For example:</p> <p><strong>Custom Attribute Interface</strong></p> <pre><code>public interface IAttribute&lt;T&gt; { T Value { get; } } </code></pre> <p><strong>Example Custom Attribute</strong></p> <pre><code>public sealed class AbbreviationAttribute: Attribute, IAttribute&lt;string&gt; { private readonly string value; public AbbreviationAttribute(string value) { this.value = value; } public string Value { get { return this.value; } } } </code></pre> <p><strong>Method to Retrieve Custom Attribute from <code>Enum</code></strong></p> <pre><code>public static R GetAttributeValue&lt;T, R&gt;(IConvertible @enum) { R attributeValue = default(R); if (@enum != null) { FieldInfo fi = @enum.GetType().GetField(@enum.ToString()); if (fi != null) { T[] attributes = fi.GetCustomAttributes(typeof(T), false) as T[]; if (attributes != null &amp;&amp; attributes.Length &gt; 0) { IAttribute&lt;R&gt; attribute = attributes[0] as IAttribute&lt;R&gt;; if (attribute != null) { attributeValue = attribute.Value; } } } } return attributeValue; } </code></pre> <p><em><strong>Example <code>Enum</code> Using This Pattern</em></strong></p> <pre><code>public enum Download { [Abbreviation("check")] [Description("Certified")] C = 1, [Abbreviation("no-formal")] [Description("No formal certification")] NF = 2, [Abbreviation("cert-prob")] [Description("Certified with potential problems")] CP = 3 } </code></pre> <p>Both <code>Abbreviation</code> and <code>Description</code> are custom attributes that implement <code>IAttribute&lt;T&gt;</code>. My actual <code>Enum</code> has 11 possible values, and as I mentioned before it's used in 28 separate properties in my custom object. Using custom attributes seemed the best way to map this information back and forth.</p> <p>Now for the question, <em>is this the best way to accomplish this?</em> I store the <code>Enum</code> value ("C", "NF", or "CP" in the snippet above) in the database, but I need the values of the Abbreviation and Description in my code. Also, I doubt this will be the final set of custom attributes I'll need.</p> <p>Before I keep moving forward with this pattern ... <em>is it the right way to do things?</em> I'd rather fix potential problems with this approach now than have to track back and refactor later.</p>