blob: aa28e3abb3be905e6252e0c4f9b193dfcb7bfa9b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
using System;
using System.ComponentModel;
using System.Text;
namespace Gestor.Application.Helpers;
public class BindingEnumHelper
{
public static string ConcatenarDescricoesEnum<TEnum>(string valores) where TEnum : Enum
{
if (valores == null)
{
return null;
}
return ConcatenarDescricoesEnum<TEnum>(Array.ConvertAll(valores.Split(new char[1] { ',' }), int.Parse));
}
private static string ConcatenarDescricoesEnum<TEnum>(int[] valores) where TEnum : Enum
{
StringBuilder stringBuilder = new StringBuilder();
foreach (int num in valores)
{
if (Enum.IsDefined(typeof(TEnum), num))
{
string text = ObterDescricaoEnum((TEnum)Enum.ToObject(typeof(TEnum), num));
stringBuilder.Append(text + ", ");
}
else
{
stringBuilder.Append("Valor desconhecido, ");
}
}
return stringBuilder.ToString().TrimEnd(',', ' ');
}
private static string ObterDescricaoEnum<TEnum>(TEnum valor) where TEnum : Enum
{
DescriptionAttribute[] array = (DescriptionAttribute[])valor.GetType().GetField(valor.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), inherit: false);
if (array != null && array.Length != 0)
{
return array[0].Description;
}
return valor.ToString();
}
}
|