Пример #1
0
        public ApiDescriptor(Type apiType)
            : base(apiType.Name)
        {
            _apiType = apiType;
            var list = GetMethodInfos(apiType);
            _methods = new List<MethodDescriptor>(list.Count);
            _methodsDic = new Dictionary<string, MethodDescriptor>(list.Count, StringComparer.CurrentCultureIgnoreCase);

            var defaultCodes = new HashSet<int>();
            foreach (ApiCodeAttribute attr in typeof(ApiController).GetCustomAttributes(typeof(ApiCodeAttribute), true))
            {
                defaultCodes.Add(attr.Code);
            }

            var attrs = new List<ApiCodeAttribute>();
            foreach (ApiCodeAttribute attr in apiType.GetCustomAttributes(typeof(ApiCodeAttribute),true))
            {
                if (defaultCodes.Contains(attr.Code)) attr.Category = 1;
                attrs.Add(attr);
            }

            var authAttr = (ApiAuthAttribute)Attribute.GetCustomAttribute(apiType, typeof(ApiAuthAttribute));
            bool auth = authAttr != null && authAttr.NeedAuth;

            foreach (var info in list)
            {
                if (null != Attribute.GetCustomAttribute(info, typeof(ApiIgnoreAttribute))) continue;
                var methodAuthAttr = (ApiAuthAttribute)Attribute.GetCustomAttribute(info, typeof(ApiAuthAttribute));
                bool needAuth = methodAuthAttr != null ? methodAuthAttr.NeedAuth : auth;
                var item = new MethodDescriptor(info, new List<ApiCodeAttribute>(attrs), needAuth);
                _methods.Add(item);
                if (_methodsDic.ContainsKey(info.Name)) throw new ApplicationException("不支持重载");
                _methodsDic.Add(info.Name, item);
            }
        }
Пример #2
0
 private string GetResponseDocumentation(MethodDescriptor methodDescriptor)
 {
     XPathNavigator methodNode = GetMethodNode(methodDescriptor);
     return GetTagValue(methodNode, "returns");
 }
Пример #3
0
 private string GetParamDocumentation(MethodDescriptor methodDescriptor, ParamDescriptor paramDescriptor)
 {
     XPathNavigator methodNode = GetMethodNode(methodDescriptor);
     if (methodNode != null)
     {
         string parameterName = paramDescriptor.ParameterInfo.Name;
         XPathNavigator parameterNode = methodNode.SelectSingleNode(String.Format(CultureInfo.InvariantCulture, ParameterExpression, parameterName));
         if (parameterNode != null)
         {
             return parameterNode.InnerXml.Trim();
         }
     }
     return null;
 }
Пример #4
0
 private XPathNavigator GetMethodNode(MethodDescriptor methodDescriptor)
 {
     string selectExpression = String.Format(CultureInfo.InvariantCulture, MethodExpression, GetMemberName(methodDescriptor.MethodInfo));
     return _documentNavigator.SelectSingleNode(selectExpression);
 }
Пример #5
0
 private string GetMethodDocumentation(MethodDescriptor methodDescriptor)
 {
     XPathNavigator methodNode = GetMethodNode(methodDescriptor);
     return GetTagValue(methodNode, "summary");
 }
Пример #6
0
        private string GetResponseDocumentation(MethodDescriptor methodDescriptor)
        {
            XPathNavigator methodNode = GetMethodNode(methodDescriptor);

            return(GetTagValue(methodNode, "returns"));
        }
Пример #7
0
        private string GetMethodDocumentation(MethodDescriptor methodDescriptor)
        {
            XPathNavigator methodNode = GetMethodNode(methodDescriptor);

            return(GetTagValue(methodNode, "summary"));
        }
Пример #8
0
        private XPathNavigator GetMethodNode(MethodDescriptor methodDescriptor)
        {
            string selectExpression = String.Format(CultureInfo.InvariantCulture, MethodExpression, GetMemberName(methodDescriptor.MethodInfo));

            return(_documentNavigator.SelectSingleNode(selectExpression));
        }