Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass Multiple Objects in Automapper Options

I'd like to be able to pass multiple objects to Automapper via the Options dictionary, but the dictionary itself is read only.

E.g. the examples I've found show adding one item like this:

Mapper.Map<Source, Dest>(src, opt => opt.Items["Foo"] = "Bar");

But I'd like to do something more like this:

 var mappingOptions = new Dictionary<string, object>();
 mappingOptions["foo"] = "foo";
 mappingOptions["bar"] = "bar";

 var model = _mapper.Map<ThingModel>(realthing,
     opt => opt.Items = mappingOptions // readonly, can't be assigned
 );

Is adding more than one item possible, maybe just inside the LINQ?

like image 762
Paul Avatar asked Jan 22 '26 14:01

Paul


1 Answers

Do you mean like this?

Mapper.Map<Source, Dest>(src, opt => 
{
     opt.Items["foo"] = "foo";
     opt.Items["bar"] = "bar";
});
like image 134
stuartd Avatar answered Jan 25 '26 03:01

stuartd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!