51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Data;
|
|
using Cowain.Bake.Common.Enums;
|
|
|
|
namespace Cowain.Bake.Common.Converter
|
|
{
|
|
public class PalletStatusConvertor:IValueConverter
|
|
{
|
|
private string GetEnumDescription(Enum enumObj)
|
|
{
|
|
FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString());
|
|
var descriptionAttr = fieldInfo
|
|
.GetCustomAttributes(false)
|
|
.OfType<DescriptionAttribute>()
|
|
.Cast<DescriptionAttribute>()
|
|
.SingleOrDefault();
|
|
if (descriptionAttr == null)
|
|
{
|
|
return enumObj.ToString();
|
|
}
|
|
else
|
|
{
|
|
return descriptionAttr.Description;
|
|
}
|
|
}
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value == null)
|
|
{
|
|
return null;
|
|
}
|
|
value = System.Convert.ToInt32(value);
|
|
EPalletStatus status = (EPalletStatus)value;
|
|
return status.FetchDescription();
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
EPalletStatus e = EnumHelper.GetValueByDescription<EPalletStatus>((string)value);
|
|
return (int)e;
|
|
}
|
|
}
|
|
}
|