title: How to get control properties then save them to XML and load it back?
body: <p>Actually I would need 4 methodes. I'm using c# .NET 3.5 and windows forms.</p>
  
  <ol>
  <li>Get ALL control properties (also sub properites like MenuItems etc.) from current form where name matches list name //don't works ok</li>
  <li>Save results to XML //don't know how to save the results</li>
  <li>Load result from XML and </li>
  <li>finally set loaded control properties from XML. //work great</li>
  </ol>
  
  <p>Now I'm doing this form step 1:</p>
  
  <pre><code>  public static Dictionary&lt;string, object&gt; xmlDictionary;
    public Control FindControlRecursive(Control container, List&lt;string&gt; properties)
    {
       foreach (Control controls in container.Controls)
       {
          Type controlType = controls.GetType();
          PropertyInfo[] propertyInfos = controlType.GetProperties();
          foreach (PropertyInfo controlProperty in propertyInfos)
          {
             foreach (string propertyName in properties)
             {
                if (controlProperty.Name == propertyName)
                {
                   xmlDictionary.Add(controlProperty.Name, controlProperty.GetValue(controls, null));
                }
             }
          }
          Control foundCtrl = FindControlRecursive(controls, properties);
          if (foundCtrl != null)
             return foundCtrl;
  
       }
       return null;
    }
  </code></pre>
  
  <p>Calling the metod:</p>
  
  <pre><code>     List&lt;string&gt; propertyNames = new List&lt;string&gt;(); //list of all property names I want to save
  
       propertyNames.Add("Name");
       propertyNames.Add("Text");
       propertyNames.Add("Size");
  
       FindControlRecursive(this, propertyNames); //this is the current form
  </code></pre>
  
  <p>This method doesn't return all control properties and I dont know why.</p>
  
  <p>Step 4.:</p>
  
  <pre><code>//field = some new field
  //newValue = new value
      FieldInfo controlField = form.GetType().GetField(field, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
      object control = controlField.GetValue(form);
      PropertyInfo property = control.GetType().GetProperty(newValue);
      property.SetValue(control, items.Value, new object[0]);
  </code></pre>
  
  <p>Step 4 work great, but don't know how to iterate through XML reults.</p>
  
  <p>Could you please help me to solve these problems.</p>
  
  <p>Thank and best regards.</p>