From 6dcf1fcd8e194077a7d06cd2e8203434be8d12ed Mon Sep 17 00:00:00 2001 From: "agrath@gmail.com" Date: Thu, 21 Jul 2011 11:42:34 -1200 Subject: [PATCH] Slight optimisation in ExtensionMethodFinder. Previous commits fixed #30346 --- .../RazorDynamicNode/ExtensionMethodFinder.cs | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/umbraco.MacroEngines.Juno/RazorDynamicNode/ExtensionMethodFinder.cs b/umbraco.MacroEngines.Juno/RazorDynamicNode/ExtensionMethodFinder.cs index c74776af8c..ea1f6259e5 100644 --- a/umbraco.MacroEngines.Juno/RazorDynamicNode/ExtensionMethodFinder.cs +++ b/umbraco.MacroEngines.Juno/RazorDynamicNode/ExtensionMethodFinder.cs @@ -125,26 +125,30 @@ namespace umbraco.MacroEngines return null; } MethodInfo methodToExecute = null; - //Given the args, lets get the types and compare the type sequence to try and find the correct overload - var argTypes = args.ToList().ConvertAll(o => + if (methods.Count > 1) { - Expression oe = (o as Expression); - if (oe != null) + //Given the args, lets get the types and compare the type sequence to try and find the correct overload + var argTypes = args.ToList().ConvertAll(o => { - return oe.Type.FullName; + Expression oe = (o as Expression); + if (oe != null) + { + return oe.Type.FullName; + } + return o.GetType().FullName; + }); + var methodsWithArgTypes = methods.ConvertAll(method => new { method = method, types = method.GetParameters().ToList().ConvertAll(pi => pi.ParameterType.FullName) }); + var firstMatchingOverload = methodsWithArgTypes.FirstOrDefault(m => + { + return m.types.SequenceEqual(argTypes); + }); + if (firstMatchingOverload != null) + { + methodToExecute = firstMatchingOverload.method; } - return o.GetType().FullName; - }); - var methodsWithArgTypes = methods.ConvertAll(method => new { method = method, types = method.GetParameters().ToList().ConvertAll(pi => pi.ParameterType.FullName) }); - var firstMatchingOverload = methodsWithArgTypes.FirstOrDefault(m => - { - return m.types.SequenceEqual(argTypes); - }); - if (firstMatchingOverload != null) - { - methodToExecute = firstMatchingOverload.method; } - else + + if (methodToExecute == null) { MethodInfo firstMethod = methods.FirstOrDefault(); // NH: this is to ensure that it's always the correct one being chosen when using the LINQ extension methods