Use dynamic (ExpandoObject) properties as column headers in output
I have a script that produces an array of dynamic objects whose properties are all identical. It would be nice to have the output formatted as a single table whose columns are the properties of the dynamic objects rather than a table with a single column, Items, with links in each row to the Key/Value pairs.
-
Mark Hurd commented
LinqPad already provides that, but the compile time support from .NET is missing:
Dim ue = From s In Strings.Split("Name1:Value1; Name2:2" & vbCrLf & "Name1:Value2; Name2:3", vbCrLf) _
Let e=(Strings.Split(s,"; ").ToDictionary(Function(f)f.Split({":"c},2)(0),Function(f)f.Split({":"c},2)(1))) _
Select x=(Function(d As Dictionary(Of String,String))
Dim r = New Dynamic.ExpandoObject
Dim i As IDictionary(Of String,Object)=r
For Each kv In d
i.Add(kv.Key,kv.Value)
Next
Return r
End Function)(e)ue.Dump
Call (From x In ue _
Select Name1=CStr(x(0).Value), Name2=CInt(x(1).Value)).Dump'ExpandoObject not designed with VB in mind because these fail x!Name1 x!Name2 :-(