The Expando Object
The Expando object has been around for a while. In fact it was in .NET 4.0, in the ancient days of 2009.
What is the Expando Object
Technically it is the ExandoObject. It is a class in the System.Dynamic namespace. It gives you a very powerful tool by allowing you to create and remove members and values at run time.
A Use Case
I actually ran across a use case for this very object. The request was to create a Rest API that could respond quickly. For this project it had some APIs already, but they returned a vast amount of data. This new request only wanted a tiny subset of data. In fact they wanted to specify what fields would be returned in the JSON object.
At first I thought about just using a Dictionary object. I had some concerns about its performance and the complexity of our data models. Doing some searching I found or rediscovered the ExandoObject.
Creating an ExpandoObject and populating it as needed turned out to be the perfect trick. I then return this object as JSON which worked perfectly.