score:2

Accepted answer

the expression equivalent of the c# conditional ?: operator is expression.condition. while expression.ifthenelse you are using is the equivalent of c# if then else block.

both methods return conditionalexpression with test, iftrue and iffalse properties populated. the difference is that the result type of the condition is the type of the operands, while for ifthenelse it is void, hence cannot be used in query expression trees.

so the answer to your concrete question is:

var result = expression.condition(nullcheck, expression.constant(""), firstordefault);

p.s. as a side node, i'm getting several errors from your code snippet, so i had to rearrange it like this in order to get w/o error to the above line:

private static expression getlocalizedstring(expression stringexpression, supportedculture supportedculture)
{
    var expression = expression.parameter(typeof(apilocalizedstring), nameof(apilocalizedstring));

    var prop = expression.property(expression, nameof(apilocalizedstring.supportedculture));
    var value = expression.constant(supportedculture);
    var condition = expression.equal(prop, value);

    var where = expression.call(
        typeof(enumerable),
        nameof(enumerable.where),
        new type[] { typeof(apilocalizedstring) },
        stringexpression,
        expression.lambda<func<apilocalizedstring, bool>>(condition, expression));

    var first = expression.call(
        typeof(enumerable),
        nameof(enumerable.first),
        new type[] { typeof(apilocalizedstring) },
        stringexpression);

    var defaultifempty = expression.call(
        typeof(enumerable),
        nameof(enumerable.defaultifempty),
        new type[] { typeof(apilocalizedstring) },
        where,
        first);

    var select = expression.call(
        typeof(enumerable),
        nameof(enumerable.select),
        new type[] { typeof(apilocalizedstring), typeof(string) },
        defaultifempty,
        expression.lambda<func<apilocalizedstring, string>>(
            expression.property(expression, nameof(apilocalizedstring.text)),
            expression
        ));

    var firstordefault =
        expression.call(
        typeof(enumerable),
        nameof(enumerable.firstordefault),
        new type[] { typeof(string) },
        select);


    var nullcheck = expression.equal(stringexpression, expression.constant(null, stringexpression.type));
    var result = expression.condition(nullcheck, expression.constant(""), firstordefault);

    return result;
}

Related Query

More Query from same tag