none
Poor support of anonymous function 'matching'

    Question

  • This doesn't work (Any is the same as LINQ's Any except with an Ensures):

     

     var result = Any(s, char.IsWhiteSpace);
     Contract.Assert(result == Contract.Exists(s, char.IsWhiteSpace));
    

     

    However this does:

     

     Predicate<char> f = x => char.IsWhiteSpace(x);
     var result = Any(s, f);
     Contract.Assert(result == Contract.Exists(s, f));
    

     

    So it would seem that the static checker can't pick up that both usages of `char.IsWhiteSpace` are equivalent.

    The second form isn't acceptable in the long term, because you can't use the variable `f` in a Contract.Ensures, for example, and using simply `char.IsWhiteSpace` in the Ensures doesn't work because of the original issue (I presume).

    Wednesday, February 02, 2011 9:37 PM

Answers