private void Method(string methodName, Type type, Expression instance, List <Expression> argumentsList) { var argumentTypes = argumentsList.Select(x => x.Type).ToArray(); MethodInfo mi; try { mi = type.GetMethod(methodName, argumentTypes); if (mi == null && instance != null) { mi = _parserContext.FindExtensionMethod(type, methodName, argumentTypes); if (mi != null) { //In extension method instance is passed as the first argument argumentsList.Insert(0, instance); instance = null; } } } catch (AmbiguousMatchException) { var argString = string.Join(",", argumentTypes.Cast <Type>()); throw new InternalParseException($"Ambiguous method name. Type={type}, Method={methodName}, Arguments={argString}", _context); } if (mi == null) { var argString = string.Join(",", argumentTypes.Cast <Type>()); throw new InternalParseException($"Method not found. Type={type}, Method={methodName}, Arguments={argString}", _context); } var arguments = EnsureArgumentTypes(argumentsList, mi); SetExpression(Expression.Call(instance, mi, arguments)); }
private void Method(string methodName, Type type, Expression instance, List <Expression> argumentsList) { var argumentTypes = argumentsList.Select(x => x.Type).ToArray(); var mi = type.GetMethod(methodName, argumentTypes); if (mi == null && instance != null) { mi = _parserContext.FindExtensionMethod(type, methodName, argumentTypes); if (mi != null) { //In extension method instance is passed as the first argument argumentsList.Insert(0, instance); instance = null; } } if (mi == null) { throw new CompilationException($"Method not found. Type={type}, Method={methodName}", _context); } var arguments = EnsureArgumentTypes(argumentsList, mi); SetExpression(Expression.Call(instance, mi, arguments)); }