4
class A
{
  public List<string> list;
}

class B
{
  public string[] array;
}

How would you map this?

I've tried

CreateMap<A,B>();

That doesn't work

Proximo
  • 6,235
  • 11
  • 49
  • 67

2 Answers2

5

Your first issue is going to be that the class members don't match. If they did, I'd imagine that this would work. If not, you just have to specify your mapping rather than letting Automapper infer it:

CreateMap<A,B>()
    .ForMember(d => d.array, opts => opts.MapFrom(s => s.list.ToArray());
Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
  • The collection is not a string but a NameValueCollection for two different name spaces so I'm assuming those need to be mapped too. Any ideas there? – Proximo Jul 02 '14 at 19:51
  • Yes, it's because the names don't match, it has nothing to do with arrays/lists. @Proximo you might want to update your question to include the actual collection types. – Jimmy Bogard Jul 03 '14 at 13:20
  • I was going to but I figured out how to map the different internal collections individually. This answer saved the day. – Proximo Jul 03 '14 at 19:01
0

For a shortcut, a vb.net version

CreateMap(Of A, B)().ForMember(Function(d) d.array, Sub(opts) opts.MapFrom(Function(s) s.list.ToArray()))
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103