title: How to store complex object in redis hash in c#?
body: <p>I have to store complex object into hash of redis cash.I am using stackexchange.redis to do this.My Class is like below.</p>
  
  <pre><code> public class Company
     {
        public string CompanyName { get; set; }
        public List&lt;User&gt; UserList { get; set; }
     }
     public class User
     {
  
      public string Firstname { get; set; }
      public string Lastname { get; set; }
      public string Twitter { get; set; }
      public string Blog { get; set; }
     }
  </code></pre>
  
  <p>My code snippet to store data in redis is:</p>
  
  <pre><code>db.HashSet("Red:10000",comapny.ToHashEntries());
  </code></pre>
  
  <p>//Serialize in Redis format:</p>
  
  <pre><code>public static HashEntry[] ToHashEntries(this object obj)
  {
      PropertyInfo[] properties = obj.GetType().GetProperties();
      return properties
          .Where(x =&gt; x.GetValue(obj) != null) // &lt;-- PREVENT NullReferenceException
          .Select(property =&gt; new HashEntry(property.Name, property.GetValue(obj)
          .ToString())).ToArray();
  }
  </code></pre>
  
  <p>I could store the data in redis but not as i want.I am geting result as shown in below image.
  <a href="https://i.stack.imgur.com/H8PCp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H8PCp.png" alt="result after saving data in redis desktop manager"></a>
  I want <code>UserList</code> value in json format.So,how can i do this.</p>