ToolPack1
Changes
ToolPack1/Console/AutoMapperTest.cs 57(+57 -0)
ToolPack1/Console/Console.csproj 9(+9 -0)
ToolPack1/Console/packages.config 4(+4 -0)
ToolPack1/Console/Program.cs 14(+13 -1)
Details
ToolPack1/Console/AutoMapperTest.cs 57(+57 -0)
diff --git a/ToolPack1/Console/AutoMapperTest.cs b/ToolPack1/Console/AutoMapperTest.cs
new file mode 100644
index 0000000..2fcae03
--- /dev/null
+++ b/ToolPack1/Console/AutoMapperTest.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using AutoMapper;
+
+using RW_Tool.Interface.Custom;
+
+namespace Console
+{
+ public class Entity1
+ {
+ public int ID { set; get; }
+ public string Firstname { set; get; }
+ public string Secondname { set; get; }
+ public DateTime Date { set; get; }
+
+
+ public class Transfromator : ITransformator<Entity1, Entity2>
+ {
+ protected IMapper Mapper1() =>
+ new MapperConfiguration(
+ cfg => cfg.CreateMap<Entity2, Entity1>()
+ .ForMember("Firstname", e1 => e1.MapFrom(el1 => el1.Name.Split(' ')[0]))
+ .ForMember("Secondname", e1 => e1.MapFrom(el1 => el1.Name.Split(' ')[1]))
+ .ForMember("Date", e1 => e1.MapFrom(el1 => DateTime.Parse(el1.Date)))
+ )
+ .CreateMapper();
+ protected IMapper Mapper2() =>
+ new MapperConfiguration(
+ cfg => cfg.CreateMap<Entity1, Entity2>()
+ .ForMember("Name", e1 => e1.MapFrom(el1 => el1.Firstname +" "+ el1.Secondname))
+ .ForMember("Date", e1 => e1.MapFrom(el1 => el1.Date.ToShortDateString()))
+ )
+ .CreateMapper();
+
+ public Entity1 ToEntityT1(Entity2 entity)
+ {
+ return Mapper1().Map<Entity1>(entity);
+ }
+ public Entity2 ToEntityT2(Entity1 entity)
+ {
+ return Mapper2().Map<Entity2>(entity);
+ }
+
+ }
+ }
+ public class Entity2
+ {
+ public int ID { set; get; }
+ public string Name { set; get; }
+ public string Date { set; get; }
+ }
+
+}
ToolPack1/Console/Console.csproj 9(+9 -0)
diff --git a/ToolPack1/Console/Console.csproj b/ToolPack1/Console/Console.csproj
index e2fcce8..b4a79b9 100644
--- a/ToolPack1/Console/Console.csproj
+++ b/ToolPack1/Console/Console.csproj
@@ -33,6 +33,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="AutoMapper, Version=9.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
+ <HintPath>..\packages\AutoMapper.9.0.0\lib\net461\AutoMapper.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@@ -43,17 +46,23 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="AutoMapperTest.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
+ <None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConfigurationTool\ConfigurationTool.csproj">
<Project>{e8a983a0-ff7d-4e9a-9234-3f19ccb93700}</Project>
<Name>ConfigurationTool</Name>
</ProjectReference>
+ <ProjectReference Include="..\RW_Tool\RW_Tool.csproj">
+ <Project>{78207c90-5cfa-4ded-a047-cf711cba3f86}</Project>
+ <Name>RW_Tool</Name>
+ </ProjectReference>
<ProjectReference Include="..\SingletonTool\SingletonTool.csproj">
<Project>{e69e7d23-3595-4742-ad69-9b245ce9c7b8}</Project>
<Name>SingletonTool</Name>
ToolPack1/Console/packages.config 4(+4 -0)
diff --git a/ToolPack1/Console/packages.config b/ToolPack1/Console/packages.config
new file mode 100644
index 0000000..66e6616
--- /dev/null
+++ b/ToolPack1/Console/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="AutoMapper" version="9.0.0" targetFramework="net47" />
+</packages>
\ No newline at end of file
ToolPack1/Console/Program.cs 14(+13 -1)
diff --git a/ToolPack1/Console/Program.cs b/ToolPack1/Console/Program.cs
index 0cb0e5c..e12cbbc 100644
--- a/ToolPack1/Console/Program.cs
+++ b/ToolPack1/Console/Program.cs
@@ -76,7 +76,19 @@ namespace Console
// UseApplicationPathPrefix = true
//});
-
+ var e1 = new Entity1()
+ {
+ ID = 10,
+ Firstname = "fn",
+ Secondname = "sn",
+ Date = DateTime.Now
+ };
+
+ var e2 = new Entity1.Transfromator()
+ .ToEntityT2(e1);
+
+ var e1_2 = new Entity1.Transfromator()
+ .ToEntityT1(e2);
}
}
}