jeudi 16 septembre 2021

How to apply cultureinfo to expression call in c# reflection?

I have an expression like following and using with entity framework:

    public static Expression Equals(Expression left, Expression right)
    {
        var methodInfo = typeof(string).GetMethod("Equals", new[] { typeof(string) }) ?? throw new InvalidOperationException();
        var toLowerMethod = typeof(string).GetMethod("ToLower", new Type[0]) ?? throw new InvalidOperationException();
        var trimMethod = typeof(string).GetMethod("Trim", new Type[0]) ?? throw new InvalidOperationException();

        var expr = Expression.Call(left, toLowerMethod);
        expr = Expression.Call(expr, trimMethod);
        expr = Expression.Call(expr, methodInfo, right);

        return expr;
    }

I want to add CultureInfo.InvariantCulture for typeof(string).GetMethod("ToLower" expression.

How can I do this?





Aucun commentaire:

Enregistrer un commentaire