mirror of
https://github.com/SteamAutoCracks/Steam-auto-crack.git
synced 2025-05-11 02:15:38 +02:00
43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
|
|
namespace SteamAutoCrack.Utils;
|
|
|
|
public class EnumDescriptionConverter : IValueConverter
|
|
{
|
|
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
var myEnum = (Enum)value;
|
|
var description = GetEnumDescription(myEnum);
|
|
return description;
|
|
}
|
|
|
|
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
private string GetEnumDescription(Enum enumObj)
|
|
{
|
|
var fieldInfo = enumObj.GetType().GetField(enumObj.ToString());
|
|
var attribArray = fieldInfo?.GetCustomAttributes(false);
|
|
|
|
if (attribArray == null || attribArray.Length == 0)
|
|
{
|
|
return enumObj.ToString();
|
|
}
|
|
|
|
DescriptionAttribute? attrib = null;
|
|
|
|
foreach (var att in attribArray)
|
|
if (att is DescriptionAttribute)
|
|
attrib = att as DescriptionAttribute;
|
|
|
|
if (attrib != null)
|
|
return attrib.Description;
|
|
|
|
return enumObj.ToString();
|
|
}
|
|
}
|