I have a library working on expression trees. The library need to work with both C# and VB.Net
Noticed some differences between the languages on how the expression trees are constructed
String comparison
() => "a" == "b"
becomesExpression.Equals("a", "b")
Function() "a" = "b"
becomesExpression.Equals(Expression.Call(CompareString, "a", "b"), 0)
(I understand why VB.Net uses CompareString here)String concatenation
() => "a" + "b"
becomesExpression.Add("a", "b", String.Concat)
Function() "a" & "b"
becomesExpression.Call(String.Concat, "a", "b")
Optimization?
() => !(1 == 2)
becomesExpression.Not(Expression.Equals(1, 2))
Function() Not (1 = 2)
becomesExpression.NotEqual(1, 2)
My library handle all these differences but are there more differences I need to look out for?
Edit Some explanation of what my code does.
The system I work with has a filter for documents that you specify like this:
var filter = document.Filter;
filter.LeftParanthesis();
filter.Column(columnNumber);
filter.Equals();
filter.Value("abc");
filter.RightParanthesis();
filter.And();
filter.LeftParanthesis();
...
document.Refresh();
To make it easier to use the filter my code allows you to specify the filter as a Expression<Func<bool>>
lambda.
Expression<Func<bool>> filter = () => (123.AsStringColumn() == "abc") && (...);
filter.Apply(document);
My code then iterates the expression tree and calls the document filter methods as specified above. The filter does not have support for everything you can put into a lambda. Method calls is the most obvious one.
Since VB.Net generates method calls in some cases where C# does not I need to intercept these and handle them differently.