Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Common / AutoMapperConfiguration / Demos / CustomMappingDemo.cs
diff options
context:
space:
mode:
1 files changed, 36 insertions, 0 deletions
-rw-r--r--src/Common/AutoMapperConfiguration/Demos/CustomMappingDemo.cs36
diff --git a/src/Common/AutoMapperConfiguration/Demos/CustomMappingDemo.cs b/src/Common/AutoMapperConfiguration/Demos/CustomMappingDemo.cs
new file mode 100644
index 0000000..0ed3a96
--- /dev/null
+++ b/src/Common/AutoMapperConfiguration/Demos/CustomMappingDemo.cs
@@ -0,0 +1,36 @@
+using AutoMapper;
+
+namespace AutoMapperConfiguration.Demos
+{
+ internal class DemoOrigin : IMapTo<DemoDestination>, IHaveCustomMappings
+ {
+ public string Origin { get; set; }
+
+ public void CreateMappings(IMapperConfigurationExpression mapperConfig)
+ {
+ mapperConfig.CreateMap<DemoOrigin, DemoDestination>()
+ .ForMember(destination => destination.Destination, opts => opts.MapFrom(origin => origin.Origin));
+ }
+ }
+
+ internal class DemoDestination
+ {
+ public string Destination { get; set; }
+ }
+
+ class CustomMappingDemo
+ {
+ public void Run()
+ {
+ AutoMapperConfig.RegisterMappings(
+ typeof(DemoOrigin).Assembly.GetTypes(),
+ typeof(DemoDestination).Assembly.GetTypes());
+
+ DemoOrigin origin = new DemoOrigin();
+ origin.Origin = "Test";
+
+ DemoDestination destination = origin.To<DemoDestination>();
+ System.Console.WriteLine(destination.Destination); // Should be equal to "Test"
+ }
+ }
+}