From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../Helpers/BindingEnumHelper.cs | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Codemerx/Gestor.Application/Helpers/BindingEnumHelper.cs (limited to 'Codemerx/Gestor.Application/Helpers/BindingEnumHelper.cs') diff --git a/Codemerx/Gestor.Application/Helpers/BindingEnumHelper.cs b/Codemerx/Gestor.Application/Helpers/BindingEnumHelper.cs new file mode 100644 index 0000000..54e9330 --- /dev/null +++ b/Codemerx/Gestor.Application/Helpers/BindingEnumHelper.cs @@ -0,0 +1,56 @@ +using System; +using System.ComponentModel; +using System.Reflection; +using System.Text; + +namespace Gestor.Application.Helpers +{ + public class BindingEnumHelper + { + public BindingEnumHelper() + { + } + + public static string ConcatenarDescricoesEnum(string valores) + where TEnum : Enum + { + if (valores == null) + { + return null; + } + return BindingEnumHelper.ConcatenarDescricoesEnum(Array.ConvertAll(valores.Split(new char[] { ',' }), new Converter(int.Parse))); + } + + private static string ConcatenarDescricoesEnum(int[] valores) + where TEnum : Enum + { + StringBuilder stringBuilder = new StringBuilder(); + int[] numArray = valores; + for (int i = 0; i < (int)numArray.Length; i++) + { + int num = numArray[i]; + if (!Enum.IsDefined(typeof(TEnum), num)) + { + stringBuilder.Append("Valor desconhecido, "); + } + else + { + string str = BindingEnumHelper.ObterDescricaoEnum((TEnum)Enum.ToObject(typeof(TEnum), num)); + stringBuilder.Append(string.Concat(str, ", ")); + } + } + return stringBuilder.ToString().TrimEnd(new char[] { ',', ' ' }); + } + + private static string ObterDescricaoEnum(TEnum valor) + where TEnum : Enum + { + DescriptionAttribute[] customAttributes = (DescriptionAttribute[])valor.GetType().GetField(valor.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false); + if (customAttributes == null || customAttributes.Length == 0) + { + return valor.ToString(); + } + return customAttributes[0].Description; + } + } +} \ No newline at end of file -- cgit v1.2.3