/// <summary> /// 把<see cref="IAOPResult"/>接口转换成类实例<see cref="AOPResult"/> /// </summary> /// <param name="aop"><see cref="IAOPResult"/>接口实例</param> /// <param name="initializer">初始器</param> /// <returns><see cref="AOPResult"/>实例</returns> public static AOPResult ToAOPResult(this IAOPResult aop, Action <AOPResult> initializer) { if (aop != null) { var result = aop is AOPResult ? (AOPResult)aop : (AOPResult)AOPResult.Create(aop.ResultNo, aop.ResultDescription, aop.ResultAttachObject, aop.InnerAOPResult, aop.GetResultData()); if (initializer != null) { initializer(result); } return(result); } return(null); }
/// <summary> /// 把<see cref="Exception"/>包装成<see cref="IAOPResult"/> /// </summary> /// <param name="e"><see cref="Exception"/></param> /// <returns><see cref="IAOPResult"/></returns> public static IAOPResult ToAOPResult(this Exception e) { var key = typeof(IAOPResult); if (e.Data.Contains(key)) { var aop = e.Data[key] as IAOPResult; if (aop != null) { return(aop); } } return(AOPResult.Create(-1, e.Message, e, null)); }
/// <summary> /// 把<c>IAOPResult</c>转换成<c>IAOPResult<T></c> /// </summary> /// <typeparam name="T">附加的泛型</typeparam> /// <param name="aop">待转换的<c>IAOPResult</c></param> /// <returns>转换后的<c>IAOPResult<T></c></returns> public static IAOPResult <T> ToAOPResult <T>(this IAOPResult aop) { if (aop is IAOPResult <T> ) { return((IAOPResult <T>)aop); } var attachObject = default(T); if (aop.ResultAttachObject is T) { attachObject = (T)aop.ResultAttachObject; } return(AOPResult.Create(aop.ResultNo, aop.ResultDescription, attachObject, aop, aop.GetResultData())); }
/// <summary> /// 把<c>IAOPResult</c>转换成<c>IAOPResult<T></c> /// </summary> /// <typeparam name="T">附加的泛型</typeparam> /// <param name="aop">待转换的<c>IAOPResult</c></param> /// <param name="initializer">初始器</param> /// <returns>转换后的<c>IAOPResult<T></c></returns> public static IAOPResult <T> ToAOPResult <T>(this IAOPResult aop, Action <AOPResult <T> > initializer) { if (aop is IAOPResult <T> ) { return((IAOPResult <T>)aop); } var attachObject = default(T); if (aop.ResultAttachObject is T) { attachObject = (T)aop.ResultAttachObject; } var result = (AOPResult <T>)AOPResult.Create(aop.ResultNo, aop.ResultDescription, attachObject, aop, aop.GetResultData()); if (initializer != null) { initializer(result); } return(result); }
/// <summary> /// 把<c>IAOPResult<Q></c>转换成<c>IAOPResult<P></c> /// </summary> /// <typeparam name="Q">附加的泛型</typeparam> /// <typeparam name="P">附加的泛型</typeparam> /// <param name="result">待转换的<c>IAOPResult<T></c></param> /// <returns>转换后的<c>IAOPResult<T></c></returns> public static IAOPResult <P> ToAOPResult <Q, P>(this IAOPResult <Q> result) { return(AOPResult.Create(result.ResultNo, result.ResultDescription, default(P), result, result.GetResultData())); }
/// <summary> /// 把<c>IAOPResult<Q></c>转换成<c>IAOPResult<P></c>,其中<typeparamref name="Q"/>从<typeparamref name="P"/>派生 /// </summary> /// <typeparam name="Q">附加的泛型</typeparam> /// <typeparam name="P">附加的泛型</typeparam> /// <param name="result">待转换的<c>IAOPResult<T></c></param> /// <returns>转换后的<c>IAOPResult<T></c></returns> public static IAOPResult <P> CovertTo <Q, P>(this IAOPResult <Q> result) where Q : P { return(AOPResult.Create <P>(result.ResultNo, result.ResultDescription, result.ResultAttachObjectEx, result, result.GetResultData())); }