using System;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
public static class EnumExtensions
{
public static string GetDisplayName(this Enum enu)
{
var attr = GetDisplayAttribute(enu);
return attr != null ? attr.Name : enu.ToString();
}
public static string GetDescription(this Enum enu)
{
var attr = GetDisplayAttribute(enu);
return attr != null ? attr.Description : enu.ToString();
}
private static DisplayAttribute GetDisplayAttribute(object value)
{
Type type = value.GetType();
if (!type.IsEnum)
{
throw new ArgumentException(string.Format("Type {0} is not an enum", type));
}
// Get the enum field.
var field = type.GetField(value.ToString());
return field == null ? null : field.GetCustomAttribute<DisplayAttribute>();
}
}
Kaydol:
Kayıt Yorumları (Atom)
.net 6 mapget kullanımı
app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context => { var response = JsonConvert.Seriali...
-
COMMAND PROMPT TEMEL VE İLERİ DÜZEY ANLATIM Command Prompt komutlarını anlatmaya başlamadan önce, MS-DOS komut türlerine değinelim. Komut...
-
Komut ekranına aşagıdaki komutları yazarak windows service işlemlerini gerçekleştirebiliriz. Not : Komut ekranı (Başlat -> Çalıştır -&g...
-
IIS üzerinde angular-site.com site açılır. Add Aplication'dan aynı dizin içine "Api" klasörü seçilir. Buraya .Net Core Uygulam...
Hiç yorum yok:
Yorum Gönder