zoukankan      html  css  js  c++  java
  • C# 枚举的使用

        /// <summary>
        /// 枚举的使用
        /// 主要功能:使用枚举的值DataTypeId.Money,获取对应的Money字符串。
        /// </summary>
        public enum DataTypeId
        {
            [StringValue("Money")]
            Money = 0,
            [StringValue("Number")]
            Number = 1,
            [StringValue("Datetime")]
            Datetime = 2,
            [StringValue("LongText")]
            LongText = 3,
            [StringValue("ShortText")]
            ShortText = 4,
            [StringValue("IdeaType")]
            IdeaType = 5,
            [StringValue("Status")]
            Status = 6
        }

        //继承自定义基数的类
        public class StringValue : System.Attribute
        {
            private string _value;
            public StringValue(string value)
            {
                _value = value;
            }

            public string Value
            {
                get { return _value; }
            }
        }

        //使用枚举的值DataTypeId.Money,获取对应的Money字符串
        public class StringEnum
        {
            public static string GetStringValue(Enum value)
            {
                string output = null;
                Type type = value.GetType();

                FieldInfo fi = type.GetField(value.ToString());
                StringValue[] attrs = fi.GetCustomAttributes(typeof(StringValue),false) as StringValue[];
                if (attrs.Length > 0)
                {
                    output = attrs[0].Value;
                }
                return output;
            }

        }

  • 相关阅读:
    批处理学习总结之常用命令1
    Delphi常用数据类型
    Delphi预编译指令总结
    Delphi同步互斥总结
    MyEclipse 环境配置总结
    倒排索引
    laravel 学习相关笔记
    elasticsearch倒排索引原理
    原生sql和 TP sql怎么关联?
    elastic
  • 原文地址:https://www.cnblogs.com/wlming/p/5160242.html
Copyright © 2011-2022 走看看