narsil/Tanshu.Accounts.Contracts/Helper Functions/EnumHelper.cs

34 lines
1.6 KiB
C#
Raw Normal View History

using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Common.Helpers
{
public static class EnumHelper
{
public static string Display(this SettleOption settleOption)
{
var attribute = (DisplayAttribute)settleOption.GetType().GetField(settleOption.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false)[0];
return attribute != null ? attribute.Name : "";
}
public static bool Print(this SettleOption settleOption)
{
var attribute = (DisplayAttribute)settleOption.GetType().GetField(settleOption.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false)[0];
return attribute != null ? attribute.Print : false;
}
public static bool Visible(this SettleOption settleOption)
{
var attribute = (DisplayAttribute)settleOption.GetType().GetField(settleOption.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false)[0];
return attribute != null ? attribute.ShowInChoices : false;
}
public static DisplayAttribute Attribute(this SettleOption settleOption)
{
var attribute = (DisplayAttribute)settleOption.GetType().GetField(settleOption.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false)[0];
return attribute;
}
public static DisplayAttribute Attribute(this VoucherType settleOption)
{
var attribute = (DisplayAttribute)settleOption.GetType().GetField(settleOption.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false)[0];
return attribute;
}
}
}