#1 2024-08-05 21:50:47

rdevine
Member
Registered: 2014-02-20
Posts: 52

Copying property values via rtti

I'd like to be able to copy the (published) property values from a TSynPersistent subclass to a TOrm subclass - only the ones that match by name and type. I've been trawling through the v1 DDD code but have noticed it's not ported to v2. I can see a set of useful functions in the v2 rtti unit but is there anything elsewhere in v2 to simplify this? Or should I just use what's in the rtti unit and roll my own?

Thanks, Bob

Offline

#2 2024-08-06 11:56:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Copying property values via rtti

My guess is that CopyObject() from mormot.core.rtti could do this.

But by default, not with the same exact type.
I have added an option to customize CopyObject() overloaded functions.
See https://github.com/synopse/mORMot2/commit/a1cf9893

Offline

#3 2024-08-06 20:04:36

mrbar2000
Member
From: Brazil
Registered: 2016-10-26
Posts: 90

Re: Copying property values via rtti

Arnold have u some method similar to copy values from RecordToObject and ObjectToRecord?

Offline

#4 2024-08-07 10:19:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Copying property values via rtti

I have made a huge refactoring to make it possible.

See the new RecordToObject() and ObjectToRecord() functions:
https://github.com/synopse/mORMot2/commit/df088c84

Offline

#5 2024-08-07 16:04:15

rdevine
Member
Registered: 2014-02-20
Posts: 52

Re: Copying property values via rtti

The modified CopyObject works perfectly - thank you.

Offline

#6 2024-08-07 16:40:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Copying property values via rtti

I have introduced the new TRttiMap wrapper feature.
It is designed to ease any kind of class/record, class/class or record/record field mapping.
For instance, it is a very good fit for safe and fast DTO process, and is likely to be used in the context of DDD or KDD process, perhaps in a easier way than in mORMot 1.

Please try
https://github.com/synopse/mORMot2/commit/61864d9d

Offline

#7 2024-08-13 13:55:30

mrbar2000
Member
From: Brazil
Registered: 2016-10-26
Posts: 90

Re: Copying property values via rtti

WAW!!!!!!!!!!!!!!!!!!!!!
Very very very thanks Arnold. This is a Great Feature to MORMOT. 10 points Gain

Offline

Board footer

Powered by FluxBB