枚举扩展方法 /// <summary> /// 扩展方法,获得枚举的Description /// </summary> /// <param name="value">枚举值</param> /// <param name="nameInstend">当枚举没有定义DescriptionAttribute,是否用枚举名代替,默认使用</param> /// <returns>枚举…
using System; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Prog…
public enum StatusEnum { /// <summary> /// 运行中 /// </summary> [Description("运行中")] Running = , /// <summary> /// 已关闭 /// </summary> [Description("已关闭")] Stopped = } public class EnumHelper { #region 静态方法 public…
其他扩展方法详见:https://www.cnblogs.com/zhuanjiao/p/12060937.html /// <summary> /// 扩展方法,获得枚举的Description /// </summary> /// <param name="value">枚举值</param> /// <param name="nameInstead">当枚举值没有定义DescriptionAttrib…
关键代码: using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Reflection; namespace CSharpUtilHelpV2 { /// <summary> /// 基于.NET 2.0的枚举工具类 /// </summary> public static class EnumToolV2…
/// <summary> /// 获取枚举值上的Description特性说明 /// </summary> /// <typeparam name="T">枚举类型</typeparam> /// <param name="obj">枚举值</param> /// <returns></returns> public static string GetDescript…
/// <summary> /// 获取枚举Description的Name /// </summary> /// <param name="enumName">枚举</param> /// <returns></returns> public static string GetDescription(Enum enumName) { var name = enumName.ToString(); var type…
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.ComponentModel;using System.Reflection; public partial class EnumTest : System.Web.UI.Page{    /// <summ…
首先定义一个枚举:两个值:已确认.未确认. public enum ConfirmStatusEnum { [Description("未确认")] unconfirmed = , [Description("已确认")] confirmed = } 转换枚举的方法: private void InitConfirmStatus() { ; object[] atts = null; ConfirmStatusEntity statusEntity = null;…