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

namespace ThickTcpUiInWindow.Converter
{
    public class EnumToIsCheckedConverter<TEnum> : IValueConverter
        where TEnum : struct
    {

        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            TEnum type = (TEnum)value;
            if (Enum.GetName(typeof(TEnum), type) == (parameter as string))
                return true;
            else
                return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((bool)value == true)
            {
                return Enum.Parse(typeof(TEnum), (parameter as string));
            }
            else
            {
                return null;
            }
        }

        #endregion
    }
}
