@@ -109,8 +109,13 @@ type
109
109
var
110
110
User : TUser;
111
111
User2 : TUser2;
112
+ User3 : TUser2;
112
113
job : TJob;
113
114
AutoMapper : TAutoMapper<TUser,TUser2>;
115
+ { $IFNDEF FPC}
116
+ InterfacedAutoMapper : IAutoMapper<TUser,TUser2>;
117
+ { $ENDIF}
118
+
114
119
115
120
{ TUser }
116
121
@@ -221,7 +226,30 @@ begin
221
226
// User2 := TUser2(User.Clone);
222
227
// User2 := TMapper<TUserBase>.Clone(User) as TUser2;
223
228
224
- cout(' COMPARE USER VS USER2' ,etTrace);
229
+ { $IFNDEF FPC}
230
+ InterfacedAutoMapper := TAutoMapper<TUser,TUser2>.Create;
231
+
232
+ InterfacedAutoMapper.SetOnDoMapping(
233
+ procedure(const aSrcObj : TUser; const aTargetName : string; out Value : TFlexValue)
234
+ begin
235
+ if aTargetName = ' Money' then Value := aSrcObj.Cash * 2
236
+ else if aTargetName = ' IdUser' then Value := aSrcObj.Id;
237
+ end
238
+ );
239
+
240
+ InterfacedAutoMapper.SetOnAfterMapping(
241
+ procedure(const aSrcObj : TUser; aTgtObj : TUser2)
242
+ begin
243
+ aTgtObj.Money := aSrcObj.Cash * 2 ;
244
+ aTgtObj.IdUser := aSrcObj.Id;
245
+ end
246
+ );
247
+
248
+ user3 := InterfacedAutoMapper.Map(User);
249
+
250
+ { $ENDIF}
251
+
252
+ cout(' COMPARE Instanced Mapper USER VS USER2' ,etTrace);
225
253
cout(' User.Id = %d / User2.IdUser = %d' ,[User.Id,User2.IdUser],etInfo);
226
254
cout(' User.CreationDate = %s / User2.CreationDate = %s' ,[DateTimeToStr(User.CreationDate),DateTimetoStr(User2.CreationDate)],etInfo);
227
255
cout(' User.Name = %s / User2.Name = %s' ,[User.Name ,User2.Name ],etInfo);
@@ -232,12 +260,31 @@ begin
232
260
cout(' User.Job.DateFrom = %s / User2.Job.DateFrom = %s' ,[DateTimeToStr(User.Job.DateFrom),DateTimeToStr(User2.Job.DateFrom)],etInfo);
233
261
cout(' User.Car.Model = %s / User2.Car.Model = %s' ,[User.Car.Model,User2.Car.Model],etInfo);
234
262
263
+ { $IFNDEF FPC}
264
+ cout(' COMPARE Interfaced Mapper USER VS USER3' ,etTrace);
265
+ cout(' User.Id = %d / User3.IdUser = %d' ,[User.Id,User3.IdUser],etInfo);
266
+ cout(' User.CreationDate = %s / User3.CreationDate = %s' ,[DateTimeToStr(User.CreationDate),DateTimetoStr(User3.CreationDate)],etInfo);
267
+ cout(' User.Name = %s / User3.Name = %s' ,[User.Name ,User3.Name ],etInfo);
268
+ cout(' User.Age = %d / User3.Age = %d' ,[User.Age,User3.Age],etInfo);
269
+ cout(' User.Numbers = %d / User3.Numbers = %d' ,[User.Numbers[1 ],User3.Numbers[1 ]],etInfo);
270
+ cout(' User.Cash = %d / User3.Money = %d' ,[User.Cash,User3.Money],etInfo);
271
+ cout(' User.Job.Name = %s / User3.Job.Name = %s' ,[User.Job.Name ,User3.Job.Name ],etInfo);
272
+ cout(' User.Job.DateFrom = %s / User3.Job.DateFrom = %s' ,[DateTimeToStr(User.Job.DateFrom),DateTimeToStr(User3.Job.DateFrom)],etInfo);
273
+ cout(' User.Car.Model = %s / User3.Car.Model = %s' ,[User.Car.Model,User3.Car.Model],etInfo);
274
+
275
+ { $ENDIF}
276
+
235
277
cout(' ' ,etInfo);
236
278
cout(' USER AS JSON RESULT' ,etTrace);
237
279
cout(' %s' ,[User.ToJson],etInfo);
238
280
cout(' ' ,etInfo);
239
281
cout(' USER2 AS JSON RESULT' ,etTrace);
240
282
cout(' %s' ,[User2.ToJson],etInfo);
283
+ { $IFNDEF FPC}
284
+ cout(' ' ,etInfo);
285
+ cout(' USER3 AS JSON RESULT' ,etTrace);
286
+ cout(' %s' ,[User3.ToJson],etInfo);
287
+ { $ENDIF}
241
288
242
289
finally
243
290
AutoMapper.Free;
0 commit comments