Object To Enum

1
2
3
4
5
6
7
8
9
10
11
public static T ObjectToEnum<T>(object o)
{
    try
    {
        return (T)Enum.Parse(typeof(T), o.ToString(), true);
    }catch
    {
        return default(T); //retrun 0
                                    // your code
    }
}

  

posted @   人来人往  阅读(838)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示