// This is a part of the Smart PropertyGrid Library
// Copyright (C) 2001-2006 VisualHint
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions 
// of the accompanying license agreement.

using System;
using System.Reflection;
using System.Collections.Generic;

namespace VisualHint.SmartPropertyGrid
{
    internal class FieldInfoEnumComparer : IComparer<FieldInfo>
    {
        private Type _enumType;

        public FieldInfoEnumComparer(Type enumType)
        {
            _enumType = enumType;
        }

        public int Compare(FieldInfo fi1, FieldInfo fi2)
        {
            int intValue1 = Enum.Parse(_enumType, fi1.Name).GetHashCode();
            int intValue2 = Enum.Parse(_enumType, fi2.Name).GetHashCode();

            if (intValue1 < intValue2)
                return -1;
            else if (intValue1 > intValue2)
                return 1;
            else
                return 0;
        }

    }
}
