title: How to simulate GetType().GetProperties() and PropertyInfo.GetValue() for ExpandoObject in C#
body: <p>I need to attach dynamic properties (number of properties and their names are all unknown at design and compile time, they are only known at runtime through an web service call) to an c# object.</p>
  <p>In this case, I am trying to use ExpandoObject and cast it to IDictory&lt;string, object&gt; to add the dynamic property.</p>
  <pre><code>IDictionary&lt;string, object&gt; expObj = new ExpandoObject() as IDictionary&lt;string, object&gt;;
  // items are returned by external API with dynamic number of elements with dynamic name
  foreach (Item item in items)
  {
      expObj.Add(item.Name, item.Value);
  }
  </code></pre>
  <p>The code above can add the dynamic properties to the expObj successfully.</p>
  <p>Then, I need to call some helper functions, which will call GetType().GetProperties() then loop through all the properties returned to get the value (by PropertyInfo.GetValue()), in order to do some processing logic.</p>
  <p>However, according to <a href="https://stackoverflow.com/questions/32312207/expandoobject-object-and-getproperty">ExpandoObject object and GetProperty()</a></p>
  <p>As ExpandoObject is runtime binding and does not come to the CLR level, reflection is not working in this case.</p>
  <p>Is there any way to let GetType().GetProperties() and PropertyInfo.GetValue() work or simulate the behaviour in ExpandoObject?</p>
  <p>Or my only way to go is to do some refactoring of the Helper class (add some if-then-else statements. I mean {if} it is ExpandoObject, cast it to IDictionary, and loop {else} call GetType().GetProperties() and PropertyInfo.GetValue())? It is which I want to avoid because it may be error prone.</p>
  <p>Any help is highly appreciated.</p>