init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Kreta.Ellenorzo.WebApi.VN.Logic
|
||||
{
|
||||
/// <summary>
|
||||
/// Author: Kovács Kornél (DevKornél) Created On: 2019.06.
|
||||
/// </summary>
|
||||
internal static class EnumLogic
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
public static IEnumerable<(int Id, string Nev, string Leiras)> GetEnumWithDisplayNameAttribute(Type enumType)
|
||||
{
|
||||
foreach (object item in Enum.GetValues(enumType))
|
||||
{
|
||||
(int Id, string Nev, string Leiras) returnObject = ((int)item, item.ToString(), null);
|
||||
FieldInfo fieldInfo = item.GetType().GetField(returnObject.Nev);
|
||||
|
||||
if (fieldInfo != null)
|
||||
{
|
||||
DisplayAttribute attributes = (DisplayAttribute)fieldInfo.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault();
|
||||
|
||||
if (attributes != null)
|
||||
{
|
||||
returnObject.Leiras = attributes.GetName();
|
||||
}
|
||||
}
|
||||
|
||||
yield return returnObject;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetDisplayNameAttribute<T>(T enumValue)
|
||||
{
|
||||
string nev = enumValue.ToString();
|
||||
if (string.IsNullOrWhiteSpace(nev))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
FieldInfo fieldInfo = typeof(T).GetField(nev);
|
||||
|
||||
if (fieldInfo != null)
|
||||
{
|
||||
DisplayAttribute attributes = (DisplayAttribute)fieldInfo.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault();
|
||||
|
||||
if (attributes != null)
|
||||
{
|
||||
return attributes.GetName();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue