1
This commit is contained in:
@@ -23,33 +23,35 @@ namespace BITKit
|
||||
public static string GetDisplayName(this object self)
|
||||
{
|
||||
{
|
||||
if (self.GetType().GetCustomAttribute<DisplayNameAttribute>() is { } displayNameAttribute)
|
||||
var type = self is Type t? t: self.GetType();
|
||||
if (type.GetCustomAttribute<DisplayNameAttribute>() is { } displayNameAttribute)
|
||||
{
|
||||
return displayNameAttribute.DisplayName;
|
||||
}
|
||||
#if NET5_0_OR_GREATER
|
||||
if (self.GetType().GetCustomAttribute<DisplayAttribute>() is { } displayAttribute)
|
||||
if (type.GetCustomAttribute<DisplayAttribute>() is { } displayAttribute)
|
||||
{
|
||||
return displayAttribute.Name;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
{
|
||||
if (self is Enum)
|
||||
{
|
||||
var field = self.GetType().GetField(self.ToString()!);
|
||||
if (self is not Enum) return self.ToString();
|
||||
|
||||
var field = self.GetType().GetField(self.ToString()!);
|
||||
|
||||
if(field is null) return self.ToString();
|
||||
|
||||
if (field.GetCustomAttribute<DisplayNameAttribute>() is DisplayNameAttribute displayNameAttribute)
|
||||
{
|
||||
return displayNameAttribute.DisplayName;
|
||||
}
|
||||
#if NET5_0_OR_GREATER
|
||||
if (field.GetCustomAttribute<DisplayAttribute>() is DisplayAttribute displayAttribute)
|
||||
{
|
||||
return displayAttribute.Name;
|
||||
}
|
||||
#endif
|
||||
if (field.GetCustomAttribute<DisplayNameAttribute>() is { } displayNameAttribute)
|
||||
{
|
||||
return displayNameAttribute.DisplayName;
|
||||
}
|
||||
#if NET5_0_OR_GREATER
|
||||
if (field.GetCustomAttribute<DisplayAttribute>() is { } displayAttribute)
|
||||
{
|
||||
return displayAttribute.Name;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return self.ToString();
|
||||
}
|
||||
|
Reference in New Issue
Block a user