Dynamic in C# 4.0: Introducing the ExpandoObject


Reflection comparison

You can use KORM. Object relation mapper, which has provider for MsAccess Kros.KORM.MsAccess. KORM allow materialize ADO.NET classies like DbReader to IEnumerable. For example database.ModelBuilder.Materialize(reader)

Convert ExpandoObject to DataTable

Adding properties and methods to an ExpandoObject, dynamically!

A typical dynamic setup that creates a dynamic object and adds a static amount of properties might look like this:

//src filipekberg
dynamic person = new ExpandoObject();
person.Name = "Filip";
person.Age = 24;

What is interesting about the ExpandoObject is that it implements the interface: ]IDictionary<string, Object>

So what this means is that if we cast the person-object to an IDictionary we will be able to do some really cool stuff with it. The same code above but re-written to make use of the dictionary instead could look like this:

dynamic person = new ExpandoObject();
var dictionary = (IDictionary<string, object>)person;

dictionary.Add("Name", "Filip");
dictionary.Add("Age", 24);

By: |04/03/2019|categories: