title: How can I maintain C# primitive types above RedisValue when using StackExchange.Redis
body: <p>I started using the <code>StackExchange.Redis</code> client for storing key value pairs.</p>
  
  <p>I have a nested dynamic object (<code>JObject</code>) and I flatten that object to a key-value structure that looks something like:</p>
  
  <p>Lets assume the <code>JObject</code> looks like:</p>
  
  <pre><code>"Root":
  {
     "Obj1":
      {
         "Prop":12,
         "Prop2": "StringValue"
      }
  }
  </code></pre>
  
  <p>I flatten this object into a <code>Dictionary&lt;string, object&gt;</code> that generates key value pairs that look like:</p>
  
  <pre><code>key: "Root.Obj1.Prop" | value: 12
  key: "Root.Obj1.Prop2" | value: "StringValue"
  </code></pre>
  
  <p>I'm using <code>object</code> and not <code>string</code> since my client knows how to handle various primitives (which aren't always <code>strings</code>). </p>
  
  <p>The specific redis client excepts a <code>RedisValue</code> struct which has implicit castings for multiple types but not from object.</p>
  
  <p>So I had to split my dictionary into different primitive enumerables in order to create RedisValues and to "maintain" their original types:</p>
  
  <pre><code>var strs = dic.Where(kvp =&gt; kvp.Value is string).Select(kvp =&gt; new HashEntry(kvp.Key, (string)kvp.Value));
  var ints = dic.Where(kvp =&gt; kvp.Value is int).Select(kvp =&gt; new HashEntry(kvp.Key, (int)kvp.Value));
  </code></pre>
  
  <p>Now each value in the <code>ints</code> enumerable has a IsInteger property equal to true.</p>
  
  <p>So after setting redis with those values, I'm now fetching the key-values from Redis and I have a bunch of RedisValues in my hand. I take one RedisValue which had a IsInteger property equal to true and see that it didn't really maintain that state.</p>
  
  <p>My questions:</p>
  
  <ol>
  <li><p>Is there any way I can maintain the real primitive types between sets and gets? I understand I have some boxing\unboxing issues by keeping them as 
  objects but I have lot's of benefit's in this specific app. Using a RedisValue struct isn't something that I'd like to do across my application. I'd like to keep that in a small specific layer that communicates with Redis.</p></li>
  <li><p>If theres no way to do (1) then is there any good reason why the RedisValue doesn't keep the IsInteger property between sets and gets? When I set the RedisValue I have the IsInteger property set to true and when I fetch it, it's false.</p></li>
  </ol>
  
  <p>Thank you.</p>