Today I released new 3.6 version of Camlex open source library (and Camlex.Client 1.5 for managed client applications). For those who doesn’t know about this project yet, it is library which helps to build dynamic CAML queries (i.e. queries which are built in runtime based on some parameters) via C# lambda expressions and fluent interfaces. You may see a lot of examples on this page. Also in my blog you may see other related articles about Camlex.
In new release support for explicit cast boolean expressions was added. I.e. if before you have to write expression like this:
which in turn produces the following CAML:
then now you may write in simpler way without comparing with true or false explicitly:
This record is shorter and won’t cause problems with ReSharper which may suggest you to remove not needed from its point of view comparison (in previous version it would cause exception).
In order to produce CAML with comparing with false value, use not (!) operator:
which will produce:
The same simplified syntax is available in complex conditions with && and || operations:
Also appropriate change was added to reverse engineering feature which allows to get C# representation of CAML expression with Camlex library (i.e. opposite transformation comparing with what is shown above). I.e. if you will enter the last CAML query above in Camlex online service, you will also get short version of boolean cast expressions without explicit comparison with true or false. Camlex online service was created exactly for simplifying using of Camlex.Net library for developers which worked with regular string CAML queries before.
If you have any comments or ideas for further improvements don’t hesitate to post them on discussions page on project site.