Exemple #1
0
        private static IEnumerable <TestResult> GetTestResults <S, D>(S source) where D : new()
        {
            List <TestResult> testResults = new();

            new Dictionary <string, Func <D> >
            {
                { nameof(ExpressMapper), () => ExpressMapper.Mapper.Map <S, D>(source) },
                { nameof(AgileObjects.AgileMapper), () => AgileObjects.AgileMapper.Mapper.Map(source).ToANew <D>() },
                //{ nameof(Nelibur.ObjectMapper.TinyMapper), () => Nelibur.ObjectMapper.TinyMapper.Map<D>(source) },
                { nameof(AutoMapper), () => _autoMapper.Map <D>(source) },
                { nameof(Mapster), () => source.Adapt <D>() },
                { $"{nameof(Statics)}{nameof(Statics.Mapper)}", () => Mapper <S, D> .Map(source) },
                { $"{nameof(HigLabo)}{nameof(HigLabo.Core.ObjectMapper)}", () => HigLabo.Core.ObjectMapper.Default.Map(source, new D()) },
                { nameof(FastMapper), () => FastMapper.NetCore.TypeAdapter.Adapt <S, D>(source) },
                { nameof(Omu.ValueInjecter), () => Omu.ValueInjecter.Mapper.Map <S, D>(source) },
                { nameof(PowerMapper), () => PowerMapper.Mapper.Map <S, D>(source) }
                //{ nameof(SafeMapper), () => SafeMap.Convert<S, D>(source) }
                //{ nameof(RoslynMapper), () => _roslynMapper.Map<S, D>(source) }
            }.ForEach(test =>
            {
                var testResult = new TestResult
                {
                    Library         = test.Key,
                    SourceType      = typeof(S),
                    DestinationType = typeof(D)
                };

                try
                {
                    var destination = test.Value();
                    Members.CompareEquals(
                        source,
                        destination,
                        out IEnumerable <MemberDiff> memberDiffs,
                        evaluateChildNodes: true);

                    testResult.Diffs = memberDiffs;
                }
                catch
                {
                    testResult.Err = true;
                }

                testResults.Add(testResult);
            });

            return(testResults);
        }