一个读取C#特性Description方法
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方法的更多相关文章
- 一个读取C#特性Description方法(zhuan)
class Program { static void Main(string[] args) { string str= DB.write.ToDescription(); Console.Writ ...
- 李洪强iOS开发之【Objective-C】07-自定义构造方法和description方法
知识回顾 在前面已经介绍了如何定义类和创建并初始化对象,比如有Student这个类 1.Student.h 1 #import <Foundation/Foundation.h> 2 3 ...
- Objective-C运行时编程 - 实现自动化description方法的思路及代码示例
发布自米高 | Michael - 博客园,源地址:http://www.cnblogs.com/michaellfx/p/4232205.html,转载请注明. 本文结构 基础实现 性能优化 参考 ...
- 【Objective-C】2.自定义构造方法和description方法
1.Student.h 1 #import <Foundation/Foundation.h> 2 3 @interface Student : NSObject { 4 int _age ...
- 自定义构造方法和description方法
知识回顾在第5讲中已经介绍了如何定义类和创建并初始化对象,比如有Student这个类1.Student.h 1 #import <Foundation/Foundation.h>23@in ...
- 自定义构造、description方法、SEL
[Objective-C]07-自定义构造方法和description方法 // 构造方法:用来初始化对象的方法,是个对象方法,”-"开头// 重写构造方法的目的:为了让对象创建出来,成 ...
- C#中经常使用的几种读取XML文件的方法
XML文件是一种经常使用的文件格式,比如WinForm里面的app.config以及Web程序中的web.config文件,还有很多重要的场所都有它的身影.Xml是Internet环境中跨平台的,依赖 ...
- OC的特有语法-分类Category、 类的本质、description方法、SEL、NSLog输出增强、点语法、变量作用域、@property @synthesize关键字、Id、OC语言构造方法
一. 分类-Category 1. 基本用途:Category 分类是OC特有的语言,依赖于类. ➢ 如何在不改变原来类模型的前提下,给类扩充一些方法?有2种方式 ● 继承 ● 分类(Categor ...
- 自己定义构造方法和description方法
本文文件夹 知识回想 一.自己定义构造方法 二.description方法 说明:这个Objective-C专题,是学习iOS开发的前奏,也为了让有面向对象语言开发经验的程序猿,可以高速上手Objec ...
随机推荐
- 台积电16nm工艺为什么好过三星14nm
最近,关于iPhone6s A9处理器版本的事情的话题很热,最后都闹到苹果不得不出来解释的地步,先不评判苹果一再强调的整机综合续航差2~3%的准确性,但是三星14nm工艺相比台积电16nm工艺较差已经 ...
- android 程序中res/values-v14/styles.xml报错的解决办法
从旧的ADT迁移的新的ADT时, android 程序中res/values-v14/styles.xml报错: error: Error retrieving parent for item: No ...
- 最小费用最大流MCMF zkw费用流
稀疏图慢死了...但是稠密图效果还是很好的 struct MCMF{ struct tedge{int x,y,cap,w,next;}adj[maxm];int ms,fch[maxn]; int ...
- Win8 系统下串口出现叹号 异常(10)
在网上找了些资料,自己试了一下可行,具体步骤就是把win8系统自动更新驱动的功能给关掉,然后自己下载可用的驱动.具体可以看 http://download.csdn.net/detail/wuu_ex ...
- winPcap_3_获取设备列表
获取设备列表 int pcap_findalldevs_ex ( char * source, //The 'source' is a parameter that tells the functio ...
- 开源项目AndroidUtil-采用Fragment实现TabHost
原文出自:方杰|http://fangjie.info/?p=141 转载请注明出处 学习Android也有一段时间了,感觉大部分的Android应用都有很多类似的组件,所以就打算做了这样一个开源项目 ...
- C++ STL之vector常用指令
只记载本人在ACM中常用的函数. vector,相当于动态数组,数组大小可变.声明vector以后,自动在内存中分配一块连续的内存空间进行数据存储. vector在内部进行插入.删除操作时间复杂度O( ...
- C#中DataTable行转列示例
将下面表(1)格式的数据转换为表(2)格式的数据.很明显,这是一个行转列的要求,本想在数据库中行转列,因为在数据库中行转列是比较简单的,方法可以参考本站SQLServer中(行列转换)行转列及列转行且 ...
- ASP.NET NuGet to install the mvc 5.2.2
http://www.nuget.org/packages/Microsoft.AspNet.Mvc
- Android Dialog 系统样式讲解及透明背景
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_TRADIT ...