/// <summary> /// 对失败结果进行处理 /// </summary> /// <typeparam name="T">泛型类型</typeparam> /// <param name="aop"><see cref="IAOPResult{T}"/>实例</param> /// <param name="handler">处理委托</param> /// <returns><see cref="IAOPResult{T}"/>实例</returns> public static IAOPResult <T> Failed <T>(this IAOPResult <T> aop, Action <IAOPResult <T> > handler) { if (aop.IsUnSuccess() && handler != null) { handler(aop); } return(aop); }
/// <summary> /// 对失败结果进行处理 /// </summary> /// <param name="aop"><see cref="IAOPResult{T}"/>实例</param> /// <param name="handler">处理委托</param> /// <returns><see cref="IAOPResult"/>实例</returns> public static IAOPResult Failed(this IAOPResult aop, Func <IAOPResult, IAOPResult> handler) { if (aop.IsUnSuccess() && handler != null) { aop = handler(aop); } return(aop); }
protected virtual object ResultHandle(IAOPResult aop, Type returnType, ISerializer serializer) { #if DEBUG LogService.WriteLog(this, LogLevel.DEBUG, aop.ToString()); #endif object returnValue = null; if (typeof(IAOPResult).IsAssignableFrom(returnType)) { returnValue = aop; if (returnType.IsGenericType && aop.IsUnSuccess()) //要求返回的是泛型,并且返回失败 { var aopType = aop.GetType(); if (!aopType.IsGenericType) //实际获取到的不是泛型,需要转换 { var rt = typeof(AOPResult <>).MakeGenericType(returnType.GetGenericArguments()); var instance = (AOPResult)TypeHelper.CreateObject(rt, null, false); instance.ResultNo = aop.ResultNo; instance.ResultDescription = aop.ResultDescription; returnValue = instance; } } } else if (aop.IsSuccess()) { if (returnType != typeof(void)) { if (aop.ResultAttachObject != null) { returnValue = returnType.IsInstanceOfType(aop.ResultAttachObject) ? aop.ResultAttachObject : serializer.Convert(aop.ResultAttachObject, returnType, null); } } } else { throw new RemotingException(aop.ResultNo, aop.ResultDescription); } return(returnValue); }