[nem-en] Extension methods

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Tue Jan 31 20:48:01 CET 2006


Alejandro Serrano <trupill w yahoo.es> writes:

> I attach a C# implementation of System.Query to start thinking about
> query-like expressions.

Anybody has tested it? I browsed it just for curiosity, and found
e.g. this in System.Query/SequencePartitioning.cs:

                [System.Runtime.CompilerServices.Extension]
                public static IEnumerable<T> SkipWhile<T> (
                        IEnumerable<T> source,
                        Func<T, bool> predicate)
                {
                        if (source == null || predicate == null)
                                throw new ArgumentNullException ();
                        
                        bool yield = false;
                        
                        foreach (T element in source) {
                                if (yield)
                                        yield return element;
                                else
                                        if (!predicate (element))
                                                yield = true;
                        }
                }

which doesn't yield the first element which doesn't satisfy the
predicate, or this in System.Query/SequenceNotInSpec.cs:

                [System.Runtime.CompilerServices.Extension]
                private static bool Equals<T> (
                        T first, T second)
                {
                        // Mostly, values in Enumerable<T> 
                        // sequences need to be compared using
                        // Equals and GetHashCode
                        
                        if (first == null || second == null)
                                return (first == null && second == null);
                        else
                                return ((first.Equals (second) ||
                                         first.GetHashCode () == second.GetHashCode ()));
                }

where comparing hash codes doesn't seem to make sense.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak w knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/



More information about the devel-en mailing list