Esempio n. 1
0
 public HttpRoutInfo(HttpRoutInfo hri)
 {
     _regPatternPathWithoutQuery = hri._regPatternPathWithoutQuery;
     PathParams       = hri.PathParams;
     HttpMethods      = hri.HttpMethods;
     ContractTag      = hri.ContractTag;
     Path             = hri.Path;
     QueryParams      = hri.QueryParams;
     PathWithoutQuery = hri.PathWithoutQuery;
     MergeArgType     = hri.MergeArgType;
 }
Esempio n. 2
0
        private static List <HttpRoutInfo> GetSwaggerRouts(List <HttpRoutInfo> list)
        {
            var ris = list.FindAll(i => i.HttpMethods.Count > 0);

            if (ris.Count == 0)
            {
                var ri = new HttpRoutInfo(list[0]);
                ri.HttpMethods = new List <string>();
                ri.HttpMethods.Add("POST");
                ris.Add(ri);
            }
            return(ris);
        }
Esempio n. 3
0
        private static List <HttpRoutInfo> GetSwaggerRouts(List <HttpRoutInfo> list)
        {
            var ris = list.FindAll(i => i.HttpMethods.Count > 0);

            if (ris.Count == 0)
            {
                var ri = new HttpRoutInfo(list[0]);
                ri.HttpMethods = new List <HttpMethodAttribute>();
                ri.HttpMethods.Add(new HttpPostAttribute());
                ris.Add(ri);
            }

            return(ris);
        }
Esempio n. 4
0
        public static object?[] GetInnerPureArgs(object?[] pureArgs, HttpRoutInfo hri)
        {
            //class CusObj {P1, P2}
            //in:CusObj -> P1, P2  (need convert)
            //in:CusObj, P1 -> CusObj, P1 (no change)
            List <object?> retArgs = new List <object?>();

            if (hri.MergeArgType.IsSingleValue)
            {
                var inst = pureArgs[0];
                foreach (var p in hri.MergeArgType.SingleValue !.ParameterType.GetProperties())
                {
                    retArgs.Add(Helper.GetPropertyValue(inst, p));
                }
                return(retArgs.ToArray());
            }

            return(pureArgs);
        }
Esempio n. 5
0
        private static List <HttpRoutInfo> GetRouts(Type contractType, MethodInfo methodInfo)
        {
            var    contractTrimAsync = contractType.IsDefined(typeof(HttpTrimAsyncAttribute));
            var    methodTrimAsync   = methodInfo.IsDefined(typeof(HttpTrimAsyncAttribute)) || contractTrimAsync;
            var    contractRoutes    = GetRoutAttributes(contractType);
            var    tag = contractType.GetCustomAttribute <TagAttribute>(true);
            var    methodHttpMethods = methodInfo.GetCustomAttributes <HttpMethodAttribute>(true).ToList();
            var    methodRoutes      = methodInfo.GetCustomAttributes <HttpRouteAttribute>(true).ToList();
            var    obsolete          = contractType.IsDefined(typeof(ObsoleteAttribute)) | methodInfo.IsDefined(typeof(ObsoleteAttribute));
            string contractTag       = GetTag(tag, contractType, contractTrimAsync);

            //tempInfos
            var tempInfos = new List <TempInfo>();

            foreach (var r in contractRoutes)
            {
                foreach (var m in methodHttpMethods)
                {
                    tempInfos.Add(new TempInfo(
                                      contractType,
                                      methodInfo,
                                      r.Template,
                                      m.Template,
                                      m.HttpMethod,
                                      contractTrimAsync,
                                      methodTrimAsync,
                                      m.Obsolete | obsolete | r.Obsolete
                                      ));
                }

                foreach (var mr in methodRoutes)
                {
                    tempInfos.Add(new TempInfo(
                                      contractType,
                                      methodInfo,
                                      r.Template,
                                      mr.Template,
                                      null,
                                      contractTrimAsync,
                                      methodTrimAsync,
                                      obsolete | mr.Obsolete | r.Obsolete
                                      ));
                }

                //add default
                if (methodHttpMethods.Count == 0 && methodRoutes.Count == 0)
                {
                    tempInfos.Add(new TempInfo(
                                      contractType,
                                      methodInfo,
                                      r.Template,
                                      null,
                                      null,
                                      contractTrimAsync,
                                      methodTrimAsync,
                                      obsolete | r.Obsolete
                                      ));
                }
            }

            //add default
            if (tempInfos.Count == 0)
            {
                tempInfos.Add(new TempInfo(
                                  contractType,
                                  methodInfo,
                                  null,
                                  null,
                                  null,
                                  contractTrimAsync,
                                  methodTrimAsync,
                                  obsolete
                                  ));
            }

            //merger to result.
            var ret = new List <HttpRoutInfo>();

            foreach (var group in tempInfos.GroupBy(i => i.Path))
            {
                var r = new HttpRoutInfo(contractTag, group.Key, methodInfo);
                foreach (TempInfo info in group)
                {
                    if (info.Method != null)
                    {
                        r.HttpMethods.Add(HttpMethodAttributeFactory.Create(info.Method, info.Obsolete));
                    }
                }

                ret.Add(r);
            }

            return(ret);
        }