class Program
{
static void Main(string[] args)
{
string str= DB.write.ToDescription();
Console.WriteLine(str);
Console.ReadKey();
} } public enum DB{
[Description("读")]
write=,
[Description("写")]
read=
} public static class MyException
{
/// <summary>
/// 获取枚举类型的描述
/// </summary>
/// <param name="enumeration"></param>
/// <returns></returns>
public static string ToDescription(this Enum enumeration)
{
Type type = enumeration.GetType();
MemberInfo[] memInfo = type.GetMember(enumeration.ToString());
if (null != memInfo && memInfo.Length > )
{
object[] attrs = memInfo[].GetCustomAttributes(typeof(DescriptionAttribute), false);
if (null != attrs && attrs.Length > )
return ((DescriptionAttribute)attrs[]).Description;
}
return enumeration.ToString();
} }

一个读取C#特性Description方法的更多相关文章

  1. 一个读取C#特性Description方法(zhuan)

    class Program { static void Main(string[] args) { string str= DB.write.ToDescription(); Console.Writ ...

  2. 李洪强iOS开发之【Objective-C】07-自定义构造方法和description方法

    知识回顾 在前面已经介绍了如何定义类和创建并初始化对象,比如有Student这个类 1.Student.h 1 #import <Foundation/Foundation.h> 2 3 ...

  3. Objective-C运行时编程 - 实现自动化description方法的思路及代码示例

    发布自米高 | Michael - 博客园,源地址:http://www.cnblogs.com/michaellfx/p/4232205.html,转载请注明. 本文结构 基础实现 性能优化 参考 ...

  4. 【Objective-C】2.自定义构造方法和description方法

    1.Student.h 1 #import <Foundation/Foundation.h> 2 3 @interface Student : NSObject { 4 int _age ...

  5. 自定义构造方法和description方法

    知识回顾在第5讲中已经介绍了如何定义类和创建并初始化对象,比如有Student这个类1.Student.h 1 #import <Foundation/Foundation.h>23@in ...

  6. 自定义构造、description方法、SEL

    [Objective-C]07-自定义构造方法和description方法   // 构造方法:用来初始化对象的方法,是个对象方法,”-"开头// 重写构造方法的目的:为了让对象创建出来,成 ...

  7. C#中经常使用的几种读取XML文件的方法

    XML文件是一种经常使用的文件格式,比如WinForm里面的app.config以及Web程序中的web.config文件,还有很多重要的场所都有它的身影.Xml是Internet环境中跨平台的,依赖 ...

  8. OC的特有语法-分类Category、 类的本质、description方法、SEL、NSLog输出增强、点语法、变量作用域、@property @synthesize关键字、Id、OC语言构造方法

    一. 分类-Category 1. 基本用途:Category  分类是OC特有的语言,依赖于类. ➢ 如何在不改变原来类模型的前提下,给类扩充一些方法?有2种方式 ● 继承 ● 分类(Categor ...

  9. 自己定义构造方法和description方法

    本文文件夹 知识回想 一.自己定义构造方法 二.description方法 说明:这个Objective-C专题,是学习iOS开发的前奏,也为了让有面向对象语言开发经验的程序猿,可以高速上手Objec ...

随机推荐

  1. ISO14443-4块传输的实现(卡)

    贴上自己的代码,目前测试通过,但我感觉结构不是很好,希望和大家交流共同提高. .H文件 #define ACKN -1 #define ACKY -2 #define RESEND -3 #defin ...

  2. y combinator 做的一个调查_可以学习一下

    RoR: 在网络营运平台企业中,RoR站稳使用率第一的位置.其用户包括:ZenPayroll (人力资源).Asile50 (零售平台).BackerKit (众筹平台).Rainforest (QA ...

  3. 9. memcpy() memccpy() memmove() strcpy() memset()

    部分参考: http://www.cppblog.com/kang/archive/2009/04/05/78984.html 表头文件: #include <string.h>定义函数: ...

  4. JVM探索(二)

    java has four types of garbage collectors, Serial Garbage Collector Parallel Garbage Collector CMS G ...

  5. tengine rpm制作

    最近又在centos6.4下折腾tengine了,刚好不久前看了rpm包的制作方法,所以又有了搞个rpm包的想法. 1 安装centos的开发环境集成包及tengine的依赖包 1 yum group ...

  6. Robot Framework selenium2library 常用关键字

    Selenium Library SeleniumLibrary is a Robot Framework test library that uses the popular Selenium we ...

  7. A - ACM Computer Factory - poj 3436(最大流)

    题意:有一个ACM工厂会生产一些电脑,在这个工厂里面有一些生产线,分别生产不同的零件,不过他们生产的电脑可能是一体机,所以只能一些零件加工后别的生产线才可以继续加工,比如产品A在生产线1号加工后继续前 ...

  8. Java的多线程(上)

    多线程的优点和必要性是不言而喻的. 三种方法实现多线程 1. 继承Thread class A extends Thread{ public void run() {...} } 使用时, new A ...

  9. sqlcipher移植

    一.下载代码 sqlcipher赖openssl库,首先下载openssl: [fulinux@ubuntu ~]$ git clone https://github.com/openssl/open ...

  10. oracle中split的使用

    1.创建自己的类型 VARCHAR2ARRAY CREATE OR REPLACE TYPE "VARCHAR2ARRAY" as table of varchar2(300); ...