Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Common / AutoMapperConfiguration / AutoMapperConfig.cs
diff options
context:
space:
mode:
Commit77b7ff6ca840866605204e5d501fe23dd184bd5c (patch)
Author
 ivaylo.zhelev <ivaylo.zhelev@solarwinds.com>
2021-01-24 09:25:15 +0200
Committer
 ivaylo.zhelev <ivaylo.zhelev@solarwinds.com>
2021-01-24 09:25:15 +0200
Filesb2c8fac505ad91fa829256cd70c5c63e61739de8 /src/Common/AutoMapperConfiguration/AutoMapperConfig.cs
pc-craft-77b7ff6ca840866605204e5d501fe23dd184bd5c.tar
pc-craft-77b7ff6ca840866605204e5d501fe23dd184bd5c.tar.gz
pc-craft-77b7ff6ca840866605204e5d501fe23dd184bd5c.zip
Parenta7270c59ccc3a9bdfd0101c00e763ad910057a6f (diff)
Initial Commit - Add all project files
1 files changed, 46 insertions, 0 deletions
-rw-r--r--src/Common/AutoMapperConfiguration/AutoMapperConfig.cs46
diff --git a/src/Common/AutoMapperConfiguration/AutoMapperConfig.cs b/src/Common/AutoMapperConfiguration/AutoMapperConfig.cs
new file mode 100644
index 0000000..32e9564
--- /dev/null
+++ b/src/Common/AutoMapperConfiguration/AutoMapperConfig.cs
@@ -0,0 +1,46 @@
+using AutoMapper;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace AutoMapperConfiguration
+{
+ public class AutoMapperConfig
+ {
+ public static IMapper Mapper;
+
+ public static void RegisterMappings(params Type[][] typeCollections)
+ {
+ MapperConfiguration mapperConfiguration = new MapperConfiguration(mapperConfig =>
+ {
+ foreach (var typeCollection in typeCollections)
+ {
+ foreach (var type in typeCollection)
+ {
+ List<Type> mapFromTypes = type.GetInterfaces()
+ .Where(i => i.Name.Contains("IMapFrom"))
+ .Select(i => i.GetGenericArguments()[0])
+ .ToList();
+
+ foreach (var fromType in mapFromTypes)
+ {
+ mapperConfig.CreateMap(fromType, type);
+ }
+
+ List<Type> mapToTypes = type.GetInterfaces()
+ .Where(i => i.Name.Contains("IMapTo"))
+ .Select(i => i.GetGenericArguments()[0])
+ .ToList();
+
+ foreach (var toType in mapToTypes)
+ {
+ mapperConfig.CreateMap(type, toType);
+ }
+ }
+ }
+ });
+
+ Mapper = mapperConfiguration.CreateMapper();
+ }
+ }
+}