title: Generate dynamic object from dictionary with C # Reflection
body: <p>I've been researching a bit about reflections in C # and would like to know if I use a dictionary with keys-values ​​can create an object with the variable with the name of each key in the dictionary and their values​​, the key value of that dictionary.</p>
  
  <p>I have a method that does the opposite, that extracts an object from a dictionary, this dictionary contains the keys and the class properties and their values​​, the value of the properties.</p>
  
  <p>I wonder how to do this if possible.</p>
  
  <p>Below is my method, which extracts a dictionary of an object:</p>
  
  <pre><code>protected Dictionary&lt;String, String&gt; getObjectProperty(object objeto)
  {
      Dictionary&lt;String, String&gt; dictionary = new Dictionary&lt;String, String&gt;();
  
      Type type = objeto.GetType();
      FieldInfo[] field = type.GetFields();
      PropertyInfo[] myPropertyInfo = type.GetProperties();
  
      String value = null;
  
      foreach (var propertyInfo in myPropertyInfo)
      {
          if (propertyInfo.GetIndexParameters().Length == 0)
          {
              value = (string)propertyInfo.GetValue(objeto, null);
              value = value == null ? null : value;
              dictionary.Add(propertyInfo.Name.ToString(), value);
          }
      }
  
      return dictionary;
  }
  </code></pre>