Files
everything2/EveryThing/Classess/Global.cs
David Štaleker d0fa4db3d8 Klavzule
2023-06-23 10:10:25 +02:00

34 lines
1.1 KiB
C#

using System.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
namespace EveryThing.Classess
{
public static class Global
{
public static T GetAttributeOfType<T>(this Enum iEnumType) where T : System.Attribute
{
var type = iEnumType.GetType();
var memberInfo = type.GetMember(iEnumType.ToString());
var atributi = memberInfo[0].GetCustomAttributes(typeof(T), false);
return (atributi.Length > 0) ? (T)atributi[0] : null;
}
public static List<(int EnumValue, T EnumAttribute)> GetEnumListClass<T>(this Type iEnumType,
bool iUseOrder = false) where T : System.Attribute
{
List<(int EnumValue, T EnumAttribute)> titleValue = new();
foreach (var tempEnumValue in Enum.GetValues(iEnumType).Cast<Enum>())
{
object tempObject = GetAttributeOfType<T>(tempEnumValue);
titleValue.Add((Convert.ToInt32(tempEnumValue), (T)tempObject));
}
return titleValue.ToList();
}
}
}