类型转换函数

View Code
/// <summary>
/// 转换为Decimal类型
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static decimal Hz_TypeChange_ToDecimal(this object obj)
{
    if (obj == null)
        return 0M;
    decimal DecValue = 0;
    decimal.TryParse(obj.ToString(), out DecValue);
    return DecValue;
}



/// <summary>
/// 绑定枚举变量到ArrayList
/// 显示:DisplayMember
/// 值:ValueMember
/// </summary>
/// <param name="enumType"></param>
/// <returns></returns>
public static List<ListItem> GetEnumList(System.Type enumType)
{
    List<ListItem> list = new List<ListItem>();
    foreach ( string s in Enum.GetNames(enumType) )
    {
        ListItem Li = new ListItem();
        Li.DisplayMember = s;
        Li.ValueMember = Enum.Format(enumType, Enum.Parse(enumType, s),"d");
        list.Add(Li);
    }
    return list;
}

 

posted @ 2012-09-10 09:53  宋佳莉  阅读(126)  评论(0编辑  收藏  举报