示例#1
0
        public static Type GetRType(this ParamterInfoDes paramterInfoDes, MethodInfo methodInfo = null)
        {
            Type itemType = null;

            if (methodInfo != null)
            {
                var parameterInfo = methodInfo.GetParameters().FirstOrDefault(f => f.ParameterType.FullName == paramterInfoDes.TypeFullName);
                if (parameterInfo == null)
                {
                    throw new NullReferenceException($"{methodInfo.Name},无法被路由!");
                }
                itemType = parameterInfo.ParameterType;
            }
            else
            {
                if (paramterInfoDes.Value != null)
                {
                    itemType = paramterInfoDes.Value.GetType();
                }
                else
                {
                    itemType = Type.GetType(paramterInfoDes.TypeFullName);
                }
                if (itemType.IsValueType)
                {
                    itemType = Type.GetType(paramterInfoDes.TypeFullName);
                }
            }
            return(itemType);
        }
        public static ParamterInfoDes ToParamInfo(this ApiParameterDescriptor apiParameterDescriptor)
        {
            ParamterInfoDes paramterInfoDes = null;

            if (apiParameterDescriptor != null)
            {
                paramterInfoDes = new ParamterInfoDes();
                paramterInfoDes.ParamterName = apiParameterDescriptor.Name;
                paramterInfoDes.TypeFullName = apiParameterDescriptor.ParameterType.FullName;
                paramterInfoDes.Value        = apiParameterDescriptor.Value;
            }
            return(paramterInfoDes);
        }
        public static ActionSerDes ToActionSerDes(this ApiActionDescriptor apiActionDescriptor)
        {
            ActionSerDes actionSerDes = null;

            if (apiActionDescriptor != null)
            {
                actionSerDes = new ActionSerDes();
                actionSerDes.TargetTypeFullName = apiActionDescriptor.TargetTypeFullName;
                actionSerDes.MethodName         = apiActionDescriptor.Member.Name;
                if (apiActionDescriptor.Parameters != null)
                {
                    IList <ParamterInfoDes> paramterInfoDesList = new List <ParamterInfoDes>();
                    foreach (var item in apiActionDescriptor.Parameters)
                    {
                        ParamterInfoDes paramterInfoDes = item.ToParamInfo();
                        paramterInfoDesList.Add(paramterInfoDes);
                    }
                    actionSerDes.ParamterInfoArray = paramterInfoDesList.ToArray();
                    actionSerDes.RtnInfo           = apiActionDescriptor.Return.ToRtnInfo();
                }
            }
            return(actionSerDes);
        }