Reputation: 3008
Is there a way to use FastMember ObjectReader.Create
over a list of ExpandoObject
.
Here is a simple test case that I made to test:
using FastMember;
using System;
using System.Collections.Generic;
using System.Data;
using System.Dynamic;
using System.Linq;
namespace TestReaderAsync
{
class Program
{
static void Main()
{
List<ExpandoObject> expandos = new List<ExpandoObject>();
var first = GetExpando();
var second = GetExpando();
expandos.Add(first);
expandos.Add(second);
var keys = (first as IDictionary<string, object>).Keys;
using (var reader = ObjectReader.Create(expandos, keys.ToArray()))
{
var dt = new DataTable();
dt.Load(reader);
}
}
private static ExpandoObject GetExpando()
{
ExpandoObject exp = new ExpandoObject();
exp.TryAdd("ID", "A");
exp.TryAdd("ID_2", "B");
exp.TryAdd("DATE", DateTime.Now);
exp.TryAdd("MONTH", 5);
return exp;
}
}
}
It seems that the problem is coming from the GetMembers
function in TypeAccessor
. Since ExpandoObject
is inheriting from IDictionary<string, object>
, the type has no properties and FastMember is not able to serialize each key of the dictionary. Is there a workaround to achieve it?
Basically, I perform SQL queries that got translated into expandos. I want to use ObjectReader
to bulk back the result into a database.
Upvotes: 2
Views: 696