title: What is the best way to represent a type-safe property bag in a class?
body: <p>I have a 3rd party application that provides an object with many "attributes", which are simply pairs of (string) keys and values. The value types can be either strings, DateTime, Int32 or Int64. </p>
  
  <p>I need to create my own class to represent this object, in a convenient way. I'm creating a WCF service that provides this object to clients, so I need it to be very easy and clean. </p>
  
  <p>The keys of the attributes will be presented as an Enum for the clients (to hide the information of the specific key strings of the 3rd party application). However, I'm not sure how to represent the values. Here are some of the options:</p>
  
  <p>Option 1: Have different collection per attribute values, seems ugly but will be very easy for clients to use</p>
  
  <pre><code>public class MyObject
  {
      public Dictionary&lt;MyTextAttributeKeysEnum, string&gt; TextAttributes { get; set; }
      public Dictionary&lt;MyDateAttributeKeysEnum, DateTime&gt; DateAttributes { get; set; }
      public Dictionary&lt;MyNumAttributeKeysEnum, long&gt; NumericAttributes { get; set; }
  
      public string Name { get; set; }
      public string Id{ get; set; }
  </code></pre>
  
  <p>Option 2: Convert all of the attributes to strings</p>
  
  <pre><code>public class MyObject
  {
      public Dictionary&lt;MyAttributeKeysEnum, string&gt; MyAttributes { get; set; }
  
      public string Name { get; set; }
      public string Id{ get; set; }
  </code></pre>
  
  <p>Option 3: Keep them as objects, let the clients bother with casting and converting</p>
  
  <pre><code>public class MyObject
  {
      public Dictionary&lt;MyAttributeKeysEnum, object&gt; MyAttributes { get; set; }
  
      public string Name { get; set; }
      public string Id{ get; set; }
  </code></pre>