using System.Runtime.Serialization; namespace OASystem.Domain { public class Result { public int Code { get; set; } = -1; public string Msg { get; set; } = "未知错误"; public dynamic? Data { get; set; } = new { }; public Result() { } public Result(int code, string msg) { Code = code; Msg = msg; Data = null; } public Result(int code, string msg, dynamic? data = null) { Code = code; Msg = msg; Data = data; } } /// /// 业务异常基类 /// [Serializable] // 核心:添加序列化特性(IIS识别的关键) public class BusinessException : Exception { /// /// 错误代码 /// public int Code { get; set; } /// /// 错误消息 /// public string Msg { get; set; } /// /// 错误详情 /// public new object Data { get; set; } // 无参构造函数(序列化必备,即使不直接使用) public BusinessException() : base() { } public BusinessException(string message) : base(message) { Code = 400; Msg = message; } public BusinessException(int code, string message) : base(message) { Code = code; Msg = message; } public BusinessException(string message, object details) : base(message) { Code = 400; Msg = message; Data = details; } public BusinessException(int code, string message, object details) : base(message) { Code = code; Msg = message; Data = details; } public BusinessException(string message, Exception innerException) : base(message, innerException) { Code = 400; Msg = message; } // 核心:序列化构造函数(IIS反序列化时必须调用) protected BusinessException(SerializationInfo info, StreamingContext context) : base(info, context) { // 读取序列化的自定义属性(和GetObjectData对应) Code = info.GetInt32(nameof(Code)); Msg = info.GetString(nameof(Msg)); Data = info.GetValue(nameof(Data), typeof(object)); } // 核心:重写GetObjectData(序列化自定义属性) public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); // 写入自定义属性到序列化流 info.AddValue(nameof(Code), Code); info.AddValue(nameof(Msg), Msg); info.AddValue(nameof(Data), Data); } } /// /// 公共静态数据 /// public static class SharingStaticData { /// /// 端口静态数据 /// public static List PortTypes = new() { 1, 2, 3 }; } /// /// 消息 Tips /// public static class MsgTips { /// /// 成功 消息提示 /// public static string Succeed = "操作成功!"; /// /// 失败 消息提示 /// public static string Fail = "操作失败!"; /// /// 添加成功 /// public static string AddSucceed = "添加成功!"; /// /// 添加成功 /// public static string AddFail = "添加失败!"; /// /// 修改成功 /// public static string EditSucceed = "修改成功!"; /// /// 修改成功 /// public static string EditFail = "修改失败!"; /// /// 端口错误消息提示 /// public static string Port = "请检查端口值是否正确!“portType”:1:WEB;2:ANDROID;3:IOS;"; /// /// 端口错误消息提示-Mobile /// public static string MobilePort = "请检查端口值是否正确!“portType”:2:ANDROID;3:IOS;"; /// /// PageIndex 错误消息提示 /// public static string PageIndex = "请检查当前页面(pageIndex)是否正确!"; /// /// PageSize 错误消息提示 /// public static string PageSize = "请检查每页长度(pageSize)是否正确!"; /// /// 团组Id错误消息提示 /// public static string DiId = "请检查团组Id是否正确!"; /// /// 数据Id错误消息提示 /// public static string Id = "请检查数据Id(id)是否正确!"; /// /// 数据Id错误消息提示 /// public static string Status = "请检查状态Id(Status)是否正确!1 添加 2 修改"; /// /// UserId错误消息提示 /// public static string UserId = "请检查UserId是否正确!"; /// /// OperateId错误消息提示 /// public static string OperateId = "请传入有效的操作类型Id"; /// /// PageId错误消息提示 /// public static string PageId = "请检查PageId是否正确!"; /// /// CheckAuth 错误消息提示 /// public static string CheckAuth = "您没有查看权限!"; } }