首次提交:添加src文件夹代码
This commit is contained in:
50
Cowain.Bake.Common/Converter/PalletStatusConvertor.cs
Normal file
50
Cowain.Bake.Common/Converter/PalletStatusConvertor.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user