This project has moved. For the latest updates, please go here.

What about FieldId in lambdas?

Feb 2, 2010 at 7:31 AM

Hi guys!

I think thats would be very useful to add opportunity for using FieldId indexer in lambdas, cause for example in most of our projects we are using FieldId instead of Internal (Static) Name.

And also i think that type casting like this:

(string)x["Status"] == "Completed"

not elegant to look, please think about it. May be something like this

 

    public void Add<T>(Expression<Func<object,T>> expression)
    {
      //here cast by T fieldType
    }

make it more beautiful?

And thanks for project!

 

Coordinator
Feb 3, 2010 at 2:07 PM

Hello, butaji

thanks for feedback. Concerning using of Guids in Caml - it is a good idea and we will include this feature in the 2nd release.

About your idea - we wanted to leave as more natural syntax as possible. I.e. now you can use expression passed to Camlex in the regular "if" statement and will work without any changes.

One more moment - in your example

(string)x["Status"] == "Completed"

cast to string is not requred for successfull compilation as string is reference type (just Resharper will warning you about possible unintended reference comparision). But if you will use some value type (e.g. int or DateTime) - it will not be compiled without casting:

x["ID"] == 1

as indexer of SPItem has object return type. So wee need to write

(int)x["ID"] == 1

in order to compile the expression