title: Properties generated at runtime (PropertyGrid.SelectedObject)
body: <p>Ok, this is a tough one.</p>
  
  <p><strong>Introduction:</strong> My idea is to attach an instanciated QueryBuilder class which I wrote, to a PropertyGrid. The QueryBuilder class now contains a couple of fields, which are hardcoded like in the example below. Thus allowing a user to specify, which fields should be used in a query in what way (sorted, grouped, and so on). After the user having specified all the settings to these properties (by code or via the PropertyGrid GUI), the QueryBuilder is able to produce a query. Everything is working fine like that. Pseudo code:</p>
  
  <pre><code>class QueryBuilder {
    public QBField name {get; set;}
    public QBField prename {get; set;}
    public QBField zip {get; set;}
    // ...
  
    public void QueryBuilder() {
      name = new QBField();
      prename = new QBField();
      // ...
    }
  
    public getQuery() {
      // logic to build the query
    }
  }
  
  class QBField {
    public bool shown {get; set;}
    public bool sortby {get; set;}
    public bool groupby {get; set;}
  }
  </code></pre>
  
  <p><strong>Challenge:</strong> Now instead of hardcoding each field as public properties in the QueryBuilder class, I was wondering how I could use i.e. a <code>List&lt;string&gt;</code> containing all my fields to "populate" my instanciated QueryBuilder with these properties.</p>
  
  <p>So this leads to three questions:</p>
  
  <ol>
  <li><p>Could this be accomplished by somehow overriding GetProperties() of the Type of the QueryBuilder class, and if yes, how is it best done? </p></li>
  <li><p>How can I then iterate through all of these at runtime generated QBField properties and instanciate them? Idea: PropertyDescriptors and Activators?</p></li>
  <li><p>How can I iterate through all of these properties to read the values of each QBField object? The problem I ran in was, that when reading the Properties of QBField with reflection and trying getValue(obj, null), of course the first parameter needed is an object, which I do not know since I have lots of these QBField objects. Perhaps putting all my QBFields into a <code>List&lt;QBField&gt;</code> and iterating through it? Would that work in this example? </p></li>
  </ol>
  
  <p>I'm just a bit lost but I feel that I'm very close to the solution. Therefore any help or just pointers in the right direction are most greatly appreciated!</p>