You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicinterfaceICommon{}publicclassModelA:ICommon{}publicclassModelB:ICommon{}publicclassData{}publicstaticclassConverter{publicstaticExpression<Func<Data,ICommon>>ToCommonA(){return data =>newModelA();}publicstaticExpression<Func<Data,ICommon>>ToCommonB(){return data =>newModelB();}publicstaticExpression<Func<Data,ICommon>>Conditional(){Randomr=newRandom();return model =>10>r.Next(20)?ToCommonA().Invoke(model):ToCommonB().Invoke(model);}publicstaticvoidTest(){Console.WriteLine(Conditional().Expand().ToString());}}
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).
The text was updated successfully, but these errors were encountered:
#182 likely solves this for everything more recent then .NET 3.5 as 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 ConditionalExpressions and enforces the Type of both expressions to be equal.
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).
The text was updated successfully, but these errors were encountered: