24 lines
819 B
C#
24 lines
819 B
C#
![]() |
using System.ComponentModel;
|
||
|
using System.Globalization;
|
||
|
using System.Windows.Data;
|
||
|
|
||
|
namespace Seyounth.Hyosung.ViewConverter;
|
||
|
|
||
|
public class EnumDescriptionConverter : IValueConverter
|
||
|
{
|
||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||
|
{
|
||
|
if (value == null) return null;
|
||
|
|
||
|
var field = value.GetType().GetField(value.ToString() ?? string.Empty);
|
||
|
if (field == null) return null;
|
||
|
|
||
|
var attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||
|
return attributes.Length == 0 ? value.ToString() : ((DescriptionAttribute)attributes[0]).Description;
|
||
|
}
|
||
|
|
||
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||
|
{
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
}
|