using System
;
using System
.Collections
.Generic
;
using System
.Linq
;
using System
.Reflection
;
using System
.Text
;
using System
.Threading
.Tasks
;
namespace MyAttribute
.Extension
{
public enum UserState
{
[RemarkAttribute("正常")]
Normal
= 0,
[RemarkAttribute("冻结")]
Frozen
= 1,
[RemarkAttribute("删除")]
Deleted
=2
}
public class RemarkAttribute : Attribute
{
public RemarkAttribute(string remark
)
{
this._Remark
= remark
;
}
public string _Remark
= null;
public string GetRemark()
{
return this._Remark
;
}
}
public static class RemarkExtension
{
public static string GetRemark(this Enum value)
{
Type type
= value.GetType();
FieldInfo fieldInfo
= type
.GetField(value.ToString());
if (fieldInfo
.IsDefined(typeof(RemarkAttribute
),true))
{
RemarkAttribute remark
= (RemarkAttribute
)fieldInfo
.GetCustomAttribute(typeof(RemarkAttribute
),true);
return remark
.GetRemark();
}
else
{
return value.ToString();
}
}
}
}
转载请注明原文地址:https://tech.qufami.com/read-15502.html