The next generation of the Teknik Services. Written in ASP.NET.
https://www.teknik.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
54 lines
1.6 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.ComponentModel; |
|
using System.Linq; |
|
using System.Reflection; |
|
using System.Text; |
|
|
|
namespace Teknik.Utilities |
|
{ |
|
public static class Extensions |
|
{ |
|
public static string GetDescription<T>(this T value) |
|
{ |
|
FieldInfo fi = value.GetType().GetField(value.ToString()); |
|
|
|
DescriptionAttribute[] attributes = fi.GetCustomAttributes(typeof(DescriptionAttribute), false) as DescriptionAttribute[]; |
|
|
|
if (attributes != null && attributes.Any()) |
|
{ |
|
return attributes.First().Description; |
|
} |
|
|
|
return value.ToString(); |
|
} |
|
|
|
public static string GetDisplayName<T>(this T value) |
|
{ |
|
FieldInfo fi = value.GetType().GetField(value.ToString()); |
|
|
|
DisplayNameAttribute[] attributes = fi.GetCustomAttributes(typeof(DisplayNameAttribute), false) as DisplayNameAttribute[]; |
|
|
|
if (attributes != null && attributes.Any()) |
|
{ |
|
return attributes.First().DisplayName; |
|
} |
|
|
|
return value.ToString(); |
|
} |
|
|
|
public static bool IsReadOnly<T>(this T value) |
|
{ |
|
FieldInfo fi = value.GetType().GetField(value.ToString()); |
|
|
|
ReadOnlyAttribute[] attributes = fi.GetCustomAttributes(typeof(ReadOnlyAttribute), false) as ReadOnlyAttribute[]; |
|
|
|
if (attributes != null && attributes.Any()) |
|
{ |
|
return attributes.First().IsReadOnly; |
|
} |
|
|
|
return false; |
|
} |
|
} |
|
}
|
|
|