title: Cast to Anonymous Type
body: <p>I had the following problem today, and I was wondering if there is a solution for my problem.</p>
  
  <p>My idea was to build anonymous classes and use it as a datasource for a WinForm BindingSource:</p>
  
  <pre><code>public void Init()
  {
      var option1 = new
                    {
                        Id = TemplateAction.Update,
                        Option = "Update the Templates",
                        Description = "Bla bla 1."
                    };
  
      var option2 = new
                    {
                        Id = TemplateAction.Download,
                        Option = "Download the Templates",
                        Description = "Bla bla 2."
                    };
  
      var list = new[] {option1, option2}.ToList();
  
      bsOptions.DataSource = list; // my BindingSource
  
      // cboTemplates is a ComboBox
      cboTemplates.DataSource = bsOptions; 
      cboTemplates.ValueMember = "Id";
      cboTemplates.DisplayMember = "Option";
  
      lblInfoTemplates.DataBindings.Add("Text", bsOptions, "Description");
  }
  </code></pre>
  
  <p>That works fine so far.</p>
  
  <p>The problem I had is to get Id out of the "Current" property of the BindingSource, because I can't cast it back to the Anonymous Type:</p>
  
  <pre><code>private void cmdOK_Click(object sender, EventArgs e)
  {
      var option = (???)bsOptions.Current;
  }
  </code></pre>
  
  <p>I guess there is no way to find out the type of "Current" and access the "Id" Property?
  Maybe someone has a good solution...</p>
  
  <p>I know there are other (and also better) ways to get the Id (Reflection, reading the value from the ComboBox, not using anonymous tpyes,...) I'm just courious if it's possible to get the Type out of bsOptions.Current in an elegant way.</p>