From 66f34d7a1a1744d4ee4940d7232b1992bb5de15d Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 19 Sep 2024 10:23:17 +0800 Subject: [PATCH] Optimize the way to get `Map` method through reflection. Resolve #20820 --- .../Volo/Abp/ObjectMapping/DefaultObjectMapper.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/DefaultObjectMapper.cs b/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/DefaultObjectMapper.cs index 6a2ab27870..63617d2759 100644 --- a/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/DefaultObjectMapper.cs +++ b/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/DefaultObjectMapper.cs @@ -142,13 +142,20 @@ public class DefaultObjectMapper : IObjectMapper, ITransientDependency cacheKey, _ => { - return specificMapper + var method = specificMapper .GetType() - .GetMethods() - .First(x => + .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) + .FirstOrDefault(x => x.Name == nameof(IObjectMapper.Map) && x.GetParameters().Length == (destination == null ? 1 : 2) ); + + if (method == null) + { + throw new AbpException($"Could not find a method named '{nameof(IObjectMapper.Map)}' with {(destination == null ? "1" : "2")} parameters in the type '{mapperType}'."); + } + + return method; } );