agileobjects / AgileMapper

A zero-configuration, highly-configurable, unopinionated object mapper with viewable execution plans. Flattens, unflattens, deep clones, merges, updates and projects queries. .NET 3.5+ and .NET Standard 1.0+.
MIT License
460 stars 27 forks source link

Mapping mutiple nested array/list member to list object #189

Closed seanmars closed 4 years ago

seanmars commented 4 years ago

Is there have a way to mapping DataA to List<DataB>?

class DataA
{
  public List<int> Id;
  public List<string> Name;
}

class DataB
{
  public int Id;
  public string Name;
}
SteveWilkes commented 4 years ago

Hi!

There's nothing specific out of the box which will map like that, but you could map it with Linq, then plug that Linq mapping into the Mapper. I've put together a DotNetFiddle showing what I mean.

If that doesn't really fit your use case, what sort of configuration would you like to see to perform this sort of mapping?

Cheers,

Steve

seanmars commented 4 years ago

Hi @SteveWilkes,

Thanks for the solution with Linq. This solution works great for my situation. And I don't have any good idea of API/configuration to fit this case now. In this case the data I use is the daily historical stock prices. So many API using like:

{
  "date": [ "2020-01-01", "2020-01-02", "2020-01-03"],
  "open": [ 100, 200, 300],
  "close": [ 100, 200, 300],
  "high": [ 100, 200, 300],
  "low": [ 100, 200, 300]
}

So I need to mapping it.

I think the length(index) will be a problem for API/configuration.

SteveWilkes commented 4 years ago

Ahh, I see. I could see maybe supporting that out of the box at some point, but for now I'm glad the Linq solution works for you :)