hazzik / oomapper Goto Github PK
View Code? Open in Web Editor NEWObject-Obect Mapper, written in .NET
License: GNU Lesser General Public License v3.0
Object-Obect Mapper, written in .NET
License: GNU Lesser General Public License v3.0
Is it possible to merge two objects in a way that properties will be copied from source to destination only if in the source they are not NULL? Using JavaScript syntax for spread ...
operator or Object.assign()
method as an example.
var source = { Name: "X", Items: [ 1, 2, 3, 4, 5 ] }
var destination = { Name: "X", Items: [ 1, 2, 3, 4, 5 ], Count: 5 }
var res1 = { ...destination, ...source }
var res2 = Object.assign(destination, source)
res1 == res2 // True
I was able to achieve similar functionality with Automapper by checking, if the relevant property in the source
is NULL, then do not override it in the destination.
var setup = new MapperConfiguration(expression =>
{
expression
.CreateMap<DemoModel, DemoModel>()
.ForAllMembers(o => o.Condition((x, y, memberX, memberY) => memberX is not null));
};
var mapper = setup.CreateMapper();
var source = new DemoModel { Name: "X"};
var destination = new DemoModel { Name: "Y", Items: new[] { 1, 2, 3 }};
var res = mapper.Map(source, destination);
// Expected result is { Name: "X", Items: new[] { 1, 2, 3 }} so only Name property got overridden
Unfortunately, Automapper implements some ridiculously horrible behavior by clearing collections even when they're not supposed to be touched.
Question
Is merging, aka overriding only specific properties, possible in mapper without breaking collections?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.