Sorting

Posts   
 
    
PatrickHofman avatar
Posts: 14
Joined: 22-Aug-2005
# Posted on: 04-Jan-2006 15:44:37   

Hi folks,

I'm having a problem here I can't solve without your expertise wink

I have made a Sort-routine which sorts users. This is it's code:


EntityComparer<UserEntity> comparerToUse = new EntityComparer<UserEntity>((Comparison<UserEntity>)delegate(UserEntity x, UserEntity y)
{
    UserEntity[] users = new UserEntity[] { x, y };
    string[] userFullNames = new string[2];

    for (int i = 0; i < users.Length; i++)
    {
        userFullNames[i] = this.GetFullName(users[i]);
    }
    
    return String.Compare(userFullNames[0], userFullNames[1], true);
});

this.users.Sort("User", this.sortDirection, comparerToUse);

So in this case I would like to sort the existing collection containing Users with properties from that User. The problem is that whatever I try, I never reach the code in the delegate (when debugging) which is with the custom comparer.

Does anyone know what might be wrong.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 04-Jan-2006 16:16:41   

The comparer to use for sorting is for the values which are present for the field/property to sort on, not on entities. All values in the entities for the sortfield/property are stored in an arraylist and that list's quicksort algo is used while passing the comparer specified.

So it's limited at the moment to value comparing, not entity comparing. I know the sort method could give you the idea to specify a comparer for the entity.

Frans Bouma | Lead developer LLBLGen Pro