A bit of searching reveals that this is tricky. Anonymous types are created at compile time, so it is not easy to create one dynamically. This answer contains a solution using Reflection.emit
.
If possible, I would recommend just returning something like a IDictionary<,>
instead.