Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: Library for mapping one complex object to another

Tags:

c#

I'm getting a complex object from the server - lets call it ServerDTO. I want to map it to a client side object - lets call it ClientDTO.

assuming both ServerDTO & ClientDTO have the same structure inside them.

I want to map the ServerDTO object to the ClientDTO object. very simple mapping like so:

ServerDTO sd = server.Result;
ClientDTO cd = new ClientDTO();
cd.Property1 = sd.Property1;
cd.JahRas = sd. JahRas;

and so on...

so far so good.

now my question is can this mapping be done in some abstracted layer that can handle all the mapping of all my objects no matter what type or what's inside them?

so when I want to map I'll go:

ClientDTO cd = Mapper.Map(sourceServerDTO, typeOf(ClientDTO)); 
like image 715
shemesh Avatar asked Jan 31 '26 00:01

shemesh


1 Answers

You might want to look at Automapper

like image 193
Lee Avatar answered Feb 02 '26 14:02

Lee



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!