Open Azkarell opened 2 years ago
ConditionalExpression.Update
explicitly initializes the Type
of the new ConditionalExpression
to the old Type
.Currently Expression.Condition(test, ifTrue, ifFalse)
is used, which (in .NET 3.5) seems to be the only canon way to create ConditionalExpression
s and enforces the Type
of both expressions to be equal.
ConditionalExpression.Update
yourself orExpression.Condition(test, ifTrue, ifFalse, type)
, \
likely each would solve the problem.
Given following code snippets
Calling the Test method will throw an ArgumentException in Expression.Conditional because ifTrue.Type != ifFalse.Type. this can be prevented by casting the modelA/modelB to ICommon but should probably be fixed in the library, if i have the time i might even look into creating a pull request. Checking if the return type matches if not try to cast / check if it is assignable to the original type (which it should be or else the expression would not have been created in the first place).