Пример #1
0
        public CustomApi GetCustomApi(string name)
        {
            Generator generator = Generator.GetGenerator();
            CustomApi api       = generator.GetCustomApi(name);

            return(api);
        }
Пример #2
0
        /// <summary>
        /// 构造Api接口
        /// </summary>
        public void GeneratorApi()
        {
            List <MethodInfo> methodList = GetApiMethods();

            //构造Api接口
            foreach (var method in methodList)
            {
                CustomApi api = new CustomApi();
                api.Name = GetMethodAnnoatation(method);
                //Post Put
                WebInvokeAttribute webAttr = method.GetCustomAttribute <WebInvokeAttribute>();
                if (webAttr != null)
                {
                    api.RequestType = webAttr.Method;
                    api.Address     = webAttr.UriTemplate;
                    //Post Put 输入参数都是第一个
                    if (api.RequestType.Equals("POST"))
                    {
                        ParameterInfo[] paraInfos = method.GetParameters();
                        //Post参数
                        api.PostParameterList = GetParameterList(paraInfos[0]);
                        //输入参数
                        api.InParameterList = GetParameterList(1, method);
                    }
                    if (api.RequestType.Equals("PUT"))
                    {
                        ParameterInfo[] paraInfos = method.GetParameters();
                        //Put参数
                        api.PutParameterList = GetParameterList(paraInfos[0]);
                        //输入参数
                        api.InParameterList = GetParameterList(1, method);
                    }
                }
                //Get
                WebGetAttribute webGetAttr = method.GetCustomAttribute <WebGetAttribute>();
                if (webGetAttr != null)
                {
                    api.RequestType = "GET";
                    api.Address     = webGetAttr.UriTemplate;
                    ParameterInfo[] paraInfos = method.GetParameters();
                    //输入参数
                    api.InParameterList = GetParameterList(0, method);
                }
                //输出参数
                api.OutParameterList = GetCmfChinaOutParameter(method);
                _apiList.Add(api);
            }
        }