using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Haestad.Framework.UI.Integration
{
    // Source:
    // http://stackoverflow.com/questions/15486/sorting-an-ilist-in-c-sharp

    // Wraps a generic Comparison<T> delegate in an IComparer to make it easy
    // to use a lambda expression for methods that take an IComparer or IComparer<T>
    public class ComparisonComparer<T> : IComparer<T>, IComparer
    {
        private readonly Comparison<T> m_comparison;

        public ComparisonComparer(Comparison<T> comparison)
        {
            m_comparison = comparison;
        }

        public int Compare(T x, T y)
        {
            return m_comparison(x, y);
        }

        public int Compare(object o1, object o2)
        {
            return m_comparison((T)o1, (T)o2);
        }
    }
}
