Somewhat similar question here:
Difference between C# and VB.Net string comparison
...but not the same as the one I am asking now.
I am creating a simple expression walker that will convert a lambda into an SQL WHERE clause. I call it like this:
GetEntities<MyEntity>(e => e.MyProperty == MyValue)
C# creates the expression as I would expect which is a BinaryExpression
consisting of a MemberExpression
on the left and a ConstantExpression
on the right which looks like this:
$e.MyProperty == MyValue
VB.NET, however, calls CompareString
, to which it passes MyProperty
and MyValue
as parameters and then checks the return result for 0. When called like this:
GetEntities(Of MyEntity)(Function(e) e.MyProperty = MyValue)
...it generates an expression like this:
.Call Microsoft.VisualBasic.CompilerServices.Operators.CompareString(
$e.MyProperty, MyValue, False) == 0
This obviously doesn't play too well with my expression walker, so I will have to now walk the method expression to get the value passed into it and blah blah blah.
Is there a way to force VB.NET to generate the same expression tree as C# in all circumstances? I'd hate to have to write a ton of code to account for these significant differences.