Пример #1
0
        private string GetReturnDesc(MethodInfo methodInfo)
        {
            JimuServiceReturnDesc desc = new JimuServiceReturnDesc();
            var jimuReturnComment      = methodInfo.GetCustomAttribute <JimuReturnCommentAttribute>();

            if (jimuReturnComment != null)
            {
                desc.Comment      = jimuReturnComment.Comment;
                desc.ReturnFormat = jimuReturnComment.Format;
            }
            if (string.IsNullOrEmpty(desc.Comment))
            {
                var xml = GetXmlComment(methodInfo.DeclaringType);
                var key = XmlCommentsMemberNameHelper.GetMemberNameForMethod(methodInfo);
                if (xml != null && xml.TryGetValue(key, out var node))
                {
                    var returnNode = node.SelectSingleNode("returns");
                    desc.Comment = returnNode?.Value.Trim();
                }
            }

            List <Type> customTypes = new List <Type>();

            if (methodInfo.ReturnType.ToString().IndexOf("System.Threading.Tasks.Task", StringComparison.Ordinal) == 0 &&
                methodInfo.ReturnType.IsGenericType)
            {
                //desc.ReturnType = methodInfo.ReturnType.ToString();
                desc.ReturnType = string.Join(",", methodInfo.ReturnType.GenericTypeArguments.Select(x => x.FullName));
                customTypes     = (from type in methodInfo.ReturnType.GenericTypeArguments
                                   from childType in type.GenericTypeArguments
                                   select childType).ToList();
            }
            else if (methodInfo.ReturnType.IsGenericType)
            //if (methodInfo.ReturnType.IsGenericType)
            {
                //desc.ReturnType = string.Join(",", methodInfo.ReturnType.GenericTypeArguments.Select(x => x.FullName));
                desc.ReturnType = methodInfo.ReturnType.ToString();
                customTypes     = methodInfo.ReturnType.GenericTypeArguments.ToList();
            }
            else
            {
                desc.ReturnType = methodInfo.ReturnType.ToString();
                customTypes     = new List <Type> {
                    methodInfo.ReturnType
                };
            }

            // if not specify the return format in method attribute, we auto generate it.
            if (string.IsNullOrEmpty(desc.ReturnFormat))
            {
                desc.ReturnFormat = GetReturnFormat(customTypes);
            }
            return(JimuHelper.Serialize <string>(desc));
        }
Пример #2
0
        private string GetReturnDesc(MethodInfo methodInfo)
        {
            JimuServiceReturnDesc desc = new JimuServiceReturnDesc();
            var jimuReturnComment      = methodInfo.GetCustomAttribute <JimuReturnCommentAttribute>();

            if (jimuReturnComment != null)
            {
                desc.Comment      = jimuReturnComment.Comment;
                desc.ReturnFormat = jimuReturnComment.Format;
            }

            List <Type> customTypes = new List <Type>();

            //if (methodInfo.ReturnType.ToString().IndexOf("System.Threading.Tasks.Task", StringComparison.Ordinal) == 0 &&
            //          methodInfo.ReturnType.IsGenericType)
            //{
            //    desc.ReturnType = string.Join(",", methodInfo.ReturnType.GenericTypeArguments.Select(x => x.FullName));
            //    customTypes = methodInfo.ReturnType.GenericTypeArguments.ToList();
            //}
            //else if (methodInfo.ReturnType.IsGenericType)
            if (methodInfo.ReturnType.IsGenericType)
            {
                //desc.ReturnType = string.Join(",", methodInfo.ReturnType.GenericTypeArguments.Select(x => x.FullName));
                desc.ReturnType = methodInfo.ReturnType.ToString();
                customTypes     = methodInfo.ReturnType.GenericTypeArguments.ToList();
            }
            else
            {
                desc.ReturnType = methodInfo.ReturnType.ToString();
                customTypes     = new List <Type> {
                    methodInfo.ReturnType
                };
            }

            // if not specify the return format in method attribute, we auto generate it.
            if (string.IsNullOrEmpty(desc.ReturnFormat))
            {
                string format = "";
                foreach (var customType in customTypes)
                {
                    if (customType.IsClass &&
                        !customType.FullName.StartsWith("System."))
                    {
                        format = $"{{{ GetCustomTypeMembers(customType)}}},";
                    }
                    else
                    {
                        format = $"{customType.ToString()},";
                    }
                }
                desc.ReturnFormat = format.TrimEnd(',');
            }
            return(_serializer.Serialize <string>(desc));
        }
Пример #3
0
        private string GetReturnDesc(MethodInfo methodInfo)
        {
            JimuServiceReturnDesc desc = new JimuServiceReturnDesc();
            var jimuReturnComment      = methodInfo.GetCustomAttribute <JimuReturnCommentAttribute>();

            if (jimuReturnComment != null)
            {
                desc.Comment      = jimuReturnComment.Comment;
                desc.ReturnFormat = jimuReturnComment.Default;
            }
            if (string.IsNullOrEmpty(desc.Comment))
            {
                var xml = GetXmlComment(methodInfo.DeclaringType);
                var key = XmlCommentsMemberNameHelper.GetMemberNameForMethod(methodInfo);
                if (xml != null && xml.TryGetValue(key, out var node))
                {
                    var returnNode = node.SelectSingleNode("returns");
                    desc.Comment = returnNode?.Value.Trim();
                }
            }

            Type returnType = methodInfo.ReturnType;

            if (methodInfo.ReturnType.ToString().IndexOf("System.Threading.Tasks.Task", StringComparison.Ordinal) == 0)
            {
                if (methodInfo.ReturnType.GenericTypeArguments.Any())
                {
                    returnType = methodInfo.ReturnType.GenericTypeArguments[0];
                }
                else
                {
                    returnType = typeof(void);
                }
            }
            desc.ReturnType = returnType.ToString();
            if (returnType.IsGenericType && returnType.ToString().StartsWith("System."))
            {
                returnType = returnType.GenericTypeArguments[0];
            }
            else if (returnType.IsArray)
            {
                var arrayBaseType = returnType.Assembly.ExportedTypes.FirstOrDefault(x => x.FullName == returnType.FullName.TrimEnd('[', ']'));
                returnType = arrayBaseType;
            }

            if (returnType != null)
            {
                desc.Properties = GetProperties(returnType);
            }
            return(JimuHelper.Serialize <string>(desc));
        }
Пример #4
0
        private string GetReturnDesc(MethodInfo methodInfo)
        {
            JimuServiceReturnDesc desc = new JimuServiceReturnDesc();
            var jimuReturnComment      = methodInfo.GetCustomAttribute <JimuReturnCommentAttribute>();

            if (jimuReturnComment != null)
            {
                desc.Comment      = jimuReturnComment.Comment;
                desc.ReturnFormat = jimuReturnComment.Format;
            }

            List <Type> customTypes = new List <Type>();

            if (methodInfo.ReturnType.ToString().IndexOf("System.Threading.Tasks.Task", StringComparison.Ordinal) == 0 &&
                methodInfo.ReturnType.IsGenericType)
            {
                //desc.ReturnType = methodInfo.ReturnType.ToString();
                desc.ReturnType = string.Join(",", methodInfo.ReturnType.GenericTypeArguments.Select(x => x.FullName));
                customTypes     = (from type in methodInfo.ReturnType.GenericTypeArguments
                                   from childType in type.GenericTypeArguments
                                   select childType).ToList();
            }
            else if (methodInfo.ReturnType.IsGenericType)
            //if (methodInfo.ReturnType.IsGenericType)
            {
                //desc.ReturnType = string.Join(",", methodInfo.ReturnType.GenericTypeArguments.Select(x => x.FullName));
                desc.ReturnType = methodInfo.ReturnType.ToString();
                customTypes     = methodInfo.ReturnType.GenericTypeArguments.ToList();
            }
            else
            {
                desc.ReturnType = methodInfo.ReturnType.ToString();
                customTypes     = new List <Type> {
                    methodInfo.ReturnType
                };
            }

            // if not specify the return format in method attribute, we auto generate it.
            if (string.IsNullOrEmpty(desc.ReturnFormat))
            {
                desc.ReturnFormat = GetReturnFormat(customTypes);
            }
            return(_serializer.Serialize <string>(desc));
        }