private Expression BuildNullableCoalescingConditional(Expression exp)
{
if (IsNull(exp)) return null;
IEnumerator<Expression> enumerator = FindNullableExpressions(exp).GetEnumerator();
Expression root = null;
BinaryExpression and = null;
Expression lookahead = null;
while (enumerator.MoveNext())
{
Expression cur = enumerator.Current;
lookahead = enumerator.MoveNext() ? enumerator.Current : null;
if (null != and)
{
and.Right = new BinaryExpression(
BinaryOperatorType.BitwiseAnd,
and.Right,
new BinaryExpression(
BinaryOperatorType.BitwiseAnd,
CreateNullableHasValueOrTrueExpression(cur),
CreateNullableHasValueOrTrueExpression(lookahead)
)
);
}
else
{
if (null == lookahead)
return CreateNullableHasValueOrTrueExpression(cur);
root = and = new BinaryExpression(
BinaryOperatorType.BitwiseAnd,
CreateNullableHasValueOrTrueExpression(cur),
CreateNullableHasValueOrTrueExpression(lookahead));
}
}
return root;
}