From b1d7e20befe7fafdff5ea5a0195fe13a50ebcb96 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Fri, 9 Oct 2026 19:34:42 +0330 Subject: [PATCH] add support of Optional Mappin Configuration Support in MapConvert Extensions Methods ... --- Extensions/CommonExtensions.cs | 70 +++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/Extensions/CommonExtensions.cs b/Extensions/CommonExtensions.cs index 8ff338e..8664ce5 100644 --- a/Extensions/CommonExtensions.cs +++ b/Extensions/CommonExtensions.cs @@ -304,10 +304,14 @@ namespace xCommons.Extensions /// Convert Using Auto Mapper ... /// /// + /// /// /// /// - public static T MapConvert(this E source) + public static T MapConvert( + this E source, + Action cfgAction = null + ) where T : class where E : class { @@ -320,8 +324,16 @@ namespace xCommons.Extensions // var dMapConfig = new MapperConfiguration(b => { + // b.CreateMap() .ReverseMap(); + + // + // Use Specified Provided Actions if Exists ... + if (!cfgAction.IsNull()) + { + cfgAction.Invoke(b); + } }); var dMapper = dMapConfig.CreateMapper(); @@ -337,10 +349,14 @@ namespace xCommons.Extensions /// Convert Using Auto Mapper ... /// /// + /// /// /// /// - public static IEnumerable MapConvert(this IEnumerable source) + public static IEnumerable MapConvert( + this IEnumerable source, + Action cfgAction = null + ) { // if (source.IsNull()) @@ -351,8 +367,16 @@ namespace xCommons.Extensions // var dMapConfig = new MapperConfiguration(b => { + // b.CreateMap() .ReverseMap(); + + // + // Use Specified Provided Actions if Exists ... + if (!cfgAction.IsNull()) + { + cfgAction.Invoke(b); + } }); var dMapper = dMapConfig.CreateMapper(); @@ -368,10 +392,14 @@ namespace xCommons.Extensions /// Convert Using Auto Mapper ... /// /// + /// /// /// /// - public static ICollection MapConvert(this ICollection source) + public static ICollection MapConvert( + this ICollection source, + Action cfgAction = null + ) { // if (source.IsNull()) @@ -382,8 +410,16 @@ namespace xCommons.Extensions // var dMapConfig = new MapperConfiguration(b => { + // b.CreateMap() .ReverseMap(); + + // + // Use Specified Provided Actions if Exists ... + if (!cfgAction.IsNull()) + { + cfgAction.Invoke(b); + } }); var dMapper = dMapConfig.CreateMapper(); @@ -399,10 +435,14 @@ namespace xCommons.Extensions /// Convert Using Auto Mapper ... /// /// + /// /// /// /// - public static IList MapConvert(this IList source) + public static IList MapConvert( + this IList source, + Action cfgAction = null + ) { // if (source.IsNull()) @@ -413,8 +453,16 @@ namespace xCommons.Extensions // var dMapConfig = new MapperConfiguration(b => { + // b.CreateMap() .ReverseMap(); + + // + // Use Specified Provided Actions if Exists ... + if (!cfgAction.IsNull()) + { + cfgAction.Invoke(b); + } }); var dMapper = dMapConfig.CreateMapper(); @@ -430,11 +478,15 @@ namespace xCommons.Extensions /// Convert Using Auto Mapper ... /// /// + /// /// /// /// /// - public static IDictionary MapConvert(this IDictionary source) + public static IDictionary MapConvert( + this IDictionary source, + Action cfgAction = null + ) { // if (source.IsNull()) @@ -445,8 +497,16 @@ namespace xCommons.Extensions // var dMapConfig = new MapperConfiguration(b => { + // b.CreateMap() .ReverseMap(); + + // + // Use Specified Provided Actions if Exists ... + if (!cfgAction.IsNull()) + { + cfgAction.Invoke(b); + } }); var dMapper = dMapConfig.CreateMapper();