Esempio n. 1
0
        protected virtual object ResultHandle(IAOPResult aop, Type returnType, ISerializer serializer)
        {
#if DEBUG
            Logging.LogService.Debug(aop.ToString(), this);
#endif
            object returnValue = null;
            if (!typeof(IAOPResult).IsAssignableFrom(returnType))
            {
                //不是返回IAOPResult,需要去掉IAOPResult
                if (aop.ResultNo == 0)
                {
                    if (returnType != typeof(void))                      //不是无返回值
                    {
                        if (aop.ResultAttachObject != null)
                        {
                            returnValue = returnType.IsInstanceOfType(aop.ResultAttachObject) ? aop.ResultAttachObject : serializer.Convert(aop.ResultAttachObject, returnType, null);
                        }
                    }
                }
                else
                {
                    throw new ResultException(aop.ResultNo, aop.ResultDescription);
                }
            }
            else
            {
                returnValue = aop;
            }
            return(returnValue);
        }
Esempio n. 2
0
        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);
        }