日期:2014-05-18 浏览次数:21109 次
public class CustomReturnCode : Exception { private int _code; public int Code { get { return _code; } } private string _message; public override string Message { get { return _message; } } public CustomReturnCode() : base() { } public CustomReturnCode(string message) : base(message) { _code = -1; _message = message; } public CustomReturnCode(int code, string message) { _code = code; _message = message; } public void SetReturnCode(int code, string message) { _code = code; _message = message; } }
//返回执行结果的枚举 public enum CommandResult { [Description("成功")] Success = 1, [Description("Url太长")] UrlTooLong = 2, }; //枚举功能辅助 public static class EnumHelper { public static string GetEnumDescription(object enumSubitem) { enumSubitem = (Enum)enumSubitem; string strValue = enumSubitem.ToString(); FieldInfo fieldinfo = enumSubitem.GetType().GetField(strValue); if (fieldinfo != null) { Object[] objs = fieldinfo.GetCustomAttributes(typeof(DescriptionAttribute), false); if (objs == null || objs.Length == 0) { return strValue; } else { DescriptionAttribute da = (DescriptionAttribute)objs[0]; return da.Description; } } else { return ""; } } }