You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

163 lines
4.2 KiB

using System;
using ChangkeTec.Utils.CustomException;
namespace ChangkeTec.Utils
{
/// <summary>
/// 错误等级
/// </summary>
public enum ErrorLevel : byte
{
/// <summary>
/// 普通
/// </summary>
Info = 0,
/// <summary>
/// 警告
/// </summary>
Warning = 1,
/// <summary>
/// 错误
/// </summary>
Error = 2,
}
/// <summary>
/// 返回消息
/// </summary>
/// <typeparam name="T"></typeparam>
public class ReturnInfo<T> : IDisposable
{
#region 属性
/// <summary>
/// 返回值
/// </summary>
public T ReturnValue { get; set; }
/// <summary>
/// 返回消息
/// </summary>
public string ReturnText { get; set; }
/// <summary>
/// 是否执行成功
/// </summary>
public bool IsSuccess { get; set; }
/// <summary>
/// 异常等级 默认最低级
/// </summary>
public ErrorLevel ErrLevel { get; set; }
/// <summary>
/// 内部异常
/// </summary>
public Exception InnerException { get; set; }
/// <summary>
/// 计数(总数 不考虑PageSize过滤条件)
/// </summary>
public int Count { get; set; }
/// <summary>
/// 附加返回内容
/// </summary>
public object Tag { get; set; }
#endregion
#region 方法
public ReturnInfo()
{
ErrLevel = ErrorLevel.Info;
}
public void Dispose()
{
Dispose(true);
}
public void Dispose(bool disposing)
{
if (!disposing)
{
return;
}
Tag = null;
ReturnValue = default(T);
InnerException = null;
ReturnText = null;
}
public static ReturnInfo<T> ErrorInstance(Exception ex)
{
ReturnInfo<T> ri = new ReturnInfo<T>();
if ((ex is FriendlyException))
{
ri.ErrLevel = ErrorLevel.Warning;
ri.ReturnText = ex.Message;
ri.InnerException = ex;
}
else
{
ri.ErrLevel = ErrorLevel.Error;
ri.ReturnText = ex.Message;
ri.InnerException = ex;
}
return ri;
}
public static ReturnInfo<T> SuccInstance(T t)
{
ReturnInfo<T> ri = new ReturnInfo<T>();
ri.ReturnValue = t;
ri.IsSuccess = true;
return ri;
}
public static ReturnInfo<T> SuccInstance(T t, int Count)
{
ReturnInfo<T> ri = ReturnInfo<T>.SuccInstance(t);
ri.Count = Count;
return ri;
}
public static ReturnInfo<T> SuccInstance(T t, object Tag)
{
ReturnInfo<T> ri = ReturnInfo<T>.SuccInstance(t);
ri.Tag = Tag;
return ri;
}
public static ReturnInfo<T> SuccInstance(T t, string ReturnText)
{
ReturnInfo<T> ri = ReturnInfo<T>.SuccInstance(t);
ri.ReturnText = ReturnText;
return ri;
}
public static ReturnInfo<T> SuccInstance(T t, int Count, string ReturnText)
{
ReturnInfo<T> ri = ReturnInfo<T>.SuccInstance(t);
ri.Count = Count;
ri.ReturnText = ReturnText;
return ri;
}
public static ReturnInfo<T> SuccInstance(T t, int Count, object Tag)
{
ReturnInfo<T> ri = ReturnInfo<T>.SuccInstance(t);
ri.Count = Count;
ri.Tag = Tag;
return ri;
}
public static ReturnInfo<T> SuccInstance(T t, int Count, string ReturnText, object Tag)
{
ReturnInfo<T> ri = ReturnInfo<T>.SuccInstance(t);
ri.Count = Count;
ri.ReturnText = ReturnText;
ri.Tag = Tag;
return ri;
}
#endregion
}
/// <summary>
/// 返回消息 object
/// </summary>
public class ReturnInfo : ReturnInfo<object>
{
}
}