To get a comment class:
<summary>
Notes Properties
</summary>
public class Remarkattribute:attribute
{
private string M_remark;
Public Remarkattribute (string remark)
{
This.m_remark = remark;
}
<summary>
Note
</summary>
public string Remark
{
get {return m_remark;}
set {M_remark = value;}
}
<summary>
Gets the comment information for the enumeration
</summary>
<param name= "Val" > Enumeration values </param>
<returns></returns>
public static string Getenumremark (Enum val)
{
Try
{
Type type = val. GetType ();
FieldInfo fd = type. GetField (Val. ToString ());
if (FD = = null)
return string. Empty;
object[] Attrs = FD. GetCustomAttributes (typeof (Remarkattribute), false);
String name = String. Empty;
foreach (Remarkattribute attr in Attrs)
{
Name = attr. Remark;
}
return name;
}
catch (Exception ex)
{
Log4NetHelper.Log.Error ("Getenumremark Erro", ex);
return null;
}
}
}
<summary>
Enumerating extension Classes
</summary>
public static Class Enumextension
{
<summary>
Gets the comment information for the enumeration
</summary>
<param name= "em" ></param>
<returns></returns>
public static string Getremark (this Enum em)
{
Try
{
Type type = em. GetType ();
FieldInfo fd = type. GetField (em. ToString ());
if (FD = = null)
return string. Empty;
object[] Attrs = FD. GetCustomAttributes (typeof (Remarkattribute), false);
String name = String. Empty;
foreach (Remarkattribute attr in Attrs)
{
Name = attr. Remark;
}
return name;
}
catch (Exception ex)
{
Log4NetHelper.Log.Error ("Getremark Error", ex);
return null;
}
}
Enum class:
public enum Codeemun
{
<summary>
Success
</summary>
[Remark ("Success")]
SUCCESS = 1,
<summary>
Failed
</summary>
[Remark ("failure")]
FAILED = 0,
<summary>
XML Format error
</summary>
[Remark ("XML Format error")]
Xmlformaterror = 2,
<summary>
Signature Error
</summary>
[Remark ("signature error")]
Singerror = 3,
<summary>
References to objects that do not exist (for example, an order number with a wrong jest)
</summary>
[Remark ("reference to non-existent object (e.g. wrong jest order number)]
Orderiderror = 101,
<summary>
Business status is not correct
</summary>
[Remark ("Business status is incorrect")]
Statuserror = 102,
<summary>
Business cannot execute due to business constraints
</summary>
[Remark ("Business cannot be performed due to business constraints")]
Yewulimit = 103,
<summary>
Real-name authentication failed
</summary>
[Remark ("real name Authentication failed")]
Identification = 104
}
Call Method:
Codeemun Enumitem = (Codeemun) enum.parse (typeof (Investmentcommon.codeemun), notifyInfo.Code.ToString ());
String codemessage = Remarkattribute.getenumremark (Enumitem);
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
. NET enumeration (using notes)