惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
量子位
G
Google Developers Blog
J
Java Code Geeks
N
Netflix TechBlog - Medium
博客园 - 聂微东
宝玉的分享
宝玉的分享
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
雷峰网
雷峰网
M
MIT News - Artificial intelligence
T
Tailwind CSS Blog
V
Visual Studio Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss

博客园 - 南阳·源

ThinkPHP运算符与PHP运算符对照表 ThinkPHP常用配置路径 Asp.Net MVC3(三)-MvcApp实现全局异常捕获 Json数据字符串 反序列化对象时出现错误。遇到意外字符 ICSharpCode.SharpZipLib.dll压缩的zip包,7zip解压时出错 日期转换为中文日期 向大家推荐一款UI对话框框架artDialog Asp.Net MVC3(二)-过滤器定义 Asp.Net MVC3(一)-多Area时,路由设置问题 Json数据序列化对象,及对象序列化为Json格式 序列化/反序化 List<T> OrderBy问题 WCF访问安全 跨域访问WCF问题 [转] 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败 Split [转]RegistryKey 操作注册表 js控制ctrl+p sql:过滤字段中是否包含数字
C# Enum转换
南阳·源 · 2012-02-03 · via 博客园 - 南阳·源
public class Enum2
{

public Dictionary<string, int> GetEnumItems<T>()
{
Dictionary<string, int> dicResult = new Dictionary<string, int>();
T obj = default(T);
Type type = obj.GetType();
foreach (string s in type.GetEnumNames())
{
dicResult.Add(s, Convert.ToInt16((T)Enum.Parse(typeof(T), s, true)));
}
return dicResult;
}

public T GetEnumByEnumName<T>(string enumName)
{
T result = default(T);
if (Enum.IsDefined(typeof(T), enumName))
{
result = (T)Enum.Parse(typeof(T), enumName, true);
}
else
{

}
return result;
}

public T GetEnumByEnumIndex<T>(int ienum)
{
T result = default(T);
if (Enum.IsDefined(typeof(T), ienum))
{
result = (T)Enum.Parse(typeof(T), ienum.ToString(), true);
}
else
{

}
return result;
}