Closed aeslinger0 closed 5 years ago
Hi @aeslinger0 Sorry for the delay, I focused on another issue reported by you #44 and totally forgot about this one. I would like to get back to this subject if it is still a matter.
Could you provide a sample situation when this type of proposed mapping would be useful?
I think I want to take back this request. I was thinking it would be handy for the mapping function to instantiate a new object if an existing object doesn't exist. Like when you have a "Save" method that would upsert an entity. I now think it's actually better to create the new instance outside of the mapping function versus what I wrote above since you could accidentally create a new instance when you meant to update an existing instance if the existing instance could not be found (which should return an error instead). I see you already have a method for updating an existing object, so I don't think anything else needs to be done. So, nevermind :)
I think it'd be useful to allow an additional parameter that is the same as the destination type which could be used to update an existing object if it exists. So, given a signature like this:
It could generate code like this:
It should work the same if using an optional parameter:
public MyEntity Map(MyModel model, MyEntity entity = null)
What do you think?