diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:35:25 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:35:25 +0000 |
| commit | 674ca83ba9243a9e95a7568c797668dab6aee26a (patch) | |
| tree | 4a905b3fb1d827665a34d63f67bc5559f8e7235b /Gestor.Application/Helpers/BindingEnumHelper.cs | |
| download | gestor-674ca83ba9243a9e95a7568c797668dab6aee26a.tar.gz gestor-674ca83ba9243a9e95a7568c797668dab6aee26a.zip | |
feat: upload files
Diffstat (limited to 'Gestor.Application/Helpers/BindingEnumHelper.cs')
| -rw-r--r-- | Gestor.Application/Helpers/BindingEnumHelper.cs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Gestor.Application/Helpers/BindingEnumHelper.cs b/Gestor.Application/Helpers/BindingEnumHelper.cs new file mode 100644 index 0000000..54e9330 --- /dev/null +++ b/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<TEnum>(string valores)
+ where TEnum : Enum
+ {
+ if (valores == null)
+ {
+ return null;
+ }
+ return BindingEnumHelper.ConcatenarDescricoesEnum<TEnum>(Array.ConvertAll<string, int>(valores.Split(new char[] { ',' }), new Converter<string, int>(int.Parse)));
+ }
+
+ private static string ConcatenarDescricoesEnum<TEnum>(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>((TEnum)Enum.ToObject(typeof(TEnum), num));
+ stringBuilder.Append(string.Concat(str, ", "));
+ }
+ }
+ return stringBuilder.ToString().TrimEnd(new char[] { ',', ' ' });
+ }
+
+ private static string ObterDescricaoEnum<TEnum>(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 |