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. 【HDOJ】1271 整数对

    枚举,假设这个数x=a*10^(i+1)+b*10^i+c,去掉b后y=a*10^i+c,x+y=n,则x+y=n(mod10^i),求出c,注意c<10^i,但2*c有可能大于10^i,因此分 ...

  2. R语言笔记

    R语言笔记 学习R语言对我来说有好几个地方需要注意的,我觉得这样的经验也适用于学习其他的新的语言. 语言的目标 我理解语言的目标就是这个语言是用来做什么的,为什么样的任务服务的,也就是设计这个语言的动 ...

  3. HDOJ 1056 HangOver(水题)

    Problem Description How far can you make a stack of cards overhang a table? If you have one card, yo ...

  4. N - 畅通工程再续 - hdu 1875

    Description 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题 ...

  5. Class Prefix(Xcode6以后设置类前缀)

    点开Xcode右侧Utilities,Project Document->Class Prefix  图片:prefix.png 

  6. VB编写的验证码生成器

    验证码(CAPTCHA)是“Completely AutomatedPublicTuring test to tell Computers andHumansApart”(全自动区分计算机和人类的图灵 ...

  7. django 执行原始SQL

    二.知识点总结 When the model query APIs don’t go far enough, you can fall back to writing raw SQL. go far ...

  8. [置顶] ios 水果连连看游戏源码

    原创文章,转载请注明出处:http://blog.csdn.net/donny_zhang/article/details/9251917 demo功能:水果连连看游戏源码.iphone6.1 测试通 ...

  9. UITextView ios7

    UITextView *textView2 = [[UITextView alloc]initWithFrame:CGRectMake(, textView1.frame.size.height + ...

  10. IBinder对象在进程间传递的形式(一)

    命题 当service经常被远程调用时,我们经常常使用到aidl来定一个接口供service和client来使用,这个事实上就是使用Binder机制的IPC通信.当client bind servic ...