Browse Source

AutoMapper sample update

Unknown 6 years ago
parent
commit
8b66e22f41
1 changed files with 4 additions and 1 deletions
  1. 4 1
      samples/delphi/QuickAutoMapper/AutoMappingObjects.dpr

+ 4 - 1
samples/delphi/QuickAutoMapper/AutoMappingObjects.dpr

@@ -91,6 +91,7 @@ type
     fCarList : TCarList;
     fCarList : TCarList;
     fPoints : TPointsList;
     fPoints : TPointsList;
     fAgentList : TAgentList;
     fAgentList : TAgentList;
+    fJobName : string;
   public
   public
     constructor Create;
     constructor Create;
     destructor Destroy; override;
     destructor Destroy; override;
@@ -102,6 +103,7 @@ type
     property CarList : TCarList read fCarList write fCarList;
     property CarList : TCarList read fCarList write fCarList;
     property Points : TPointsList read fPoints write fPoints;
     property Points : TPointsList read fPoints write fPoints;
     property AgentList : TAgentList read fAgentList write fAgentList;
     property AgentList : TAgentList read fAgentList write fAgentList;
+    property JobName : string read fJobName write fJobName;
   end;
   end;
 
 
 var
 var
@@ -190,9 +192,10 @@ begin
     AutoMapper := TAutoMapper<TUser,TUser2>.Create;
     AutoMapper := TAutoMapper<TUser,TUser2>.Create;
     try
     try
 
 
-      //option1: you can define auto map different named properties
+      //option1: you can define auto map different named properties (if OnDoMapping assigned customaping will be no effect)
       AutoMapper.CustomMapping.AddMap('Cash','Money');
       AutoMapper.CustomMapping.AddMap('Cash','Money');
       AutoMapper.CustomMapping.AddMap('Id','IdUser');
       AutoMapper.CustomMapping.AddMap('Id','IdUser');
+      AutoMapper.CustomMapping.AddMap('Job.Name','JobName');
 
 
       //option2: you can decide to modify each property manually or allow to auto someones
       //option2: you can decide to modify each property manually or allow to auto someones
       AutoMapper.OnDoMapping := procedure(const aSrcObj : TUser; const aTargetName : string; out Value : TFlexValue)
       AutoMapper.OnDoMapping := procedure(const aSrcObj : TUser; const aTargetName : string; out Value : TFlexValue)