Imports System.Linq.Expressions
Imports System.Reflection
Imports Remotion.Linq.Clauses.Expressions
Imports Remotion.Linq.Parsing.ExpressionVisitors.Transformation
''' <summary>
''' </summary>
''' <seealso cref="Remotion.Linq.Parsing.ExpressionVisitors.Transformation.IExpressionTransformer(Of ConditionalExpression)" />
Friend Class IIFTransformer
Implements IExpressionTransformer(Of ConditionalExpression)
''' <summary>
''' Transforms a given <see cref="T:System.Linq.Expressions.Expression" />.
''' </summary>
''' <param name="expression">The expression to be transformed.</param>
''' <returns>
''' The result of the transformation, or <paramref name="expression" /> if no transformation was applied.
''' </returns>
Public Function Transform(expression As ConditionalExpression) As Expression Implements IExpressionTransformer(Of ConditionalExpression).Transform
ArgumentUtility.CheckNotNull(NameOf(expression), expression)
If (expression.Test.Type = TYPE_BOOL AndAlso expression.IfTrue.Type = TYPE_BOOL) Then
' we should rewrite the <cond1> ? <cond2> : <cond3>
' to ((<cond1> && <cond2>) || <cond3>).
Dim condition1 As Expression = expression.Test
Dim condition2 As Expression = expression.IfTrue
Dim condition3 As Expression = expression.IfFalse
Dim first As Expression = Expressions.Expression.MakeBinary(ExpressionType.AndAlso, condition1, condition2)
Return Expressions.Expression.MakeBinary(ExpressionType.OrElse, first, condition3)
Else
Return expression
End If
End Function
''' <summary>
''' Gets the expression types supported by this <see cref="IIFTransformer" />.
''' </summary>
''' <value>
''' The supported expression types.
''' </value>
Public ReadOnly Property SupportedExpressionTypes As ExpressionType() Implements IExpressionTransformer(Of ConditionalExpression).SupportedExpressionTypes
Get
Return {ExpressionType.Conditional}
End Get
End Property
End Class