Ejemplo n.º 1
0
        public MethodDescriptor(MethodInfo info, List<ApiCodeAttribute> attrs,bool needAuth)
            : base(info.Name)
        {
            _info = info;
            var paras = info.GetParameters();
            _params = new List<ParamDescriptor>(paras.Length);
            _paramsDic = new Dictionary<string, ParamDescriptor>(paras.Length, StringComparer.CurrentCultureIgnoreCase);
            foreach (var paramInfo in paras)
            {
                var item = new ParamDescriptor(paramInfo);
                _params.Add(item);
                _paramsDic.Add(paramInfo.Name, item);
            }

            _responseParameterInfo = info.ReturnParameter;

            Type t;
            if (info.ReturnParameter.ParameterType == typeof(void)) t = typeof(Response);
            else t = typeof(Response<>).MakeGenericType(info.ReturnParameter.ParameterType);

            _responseParam = new TypeDescriptor(null, t, -1);
            _responseParam.Container = Container;

            foreach (ApiCodeAttribute attr in info.GetCustomAttributes(typeof(ApiCodeAttribute), true))
            {
                attrs.Add(attr);
            }

            _responseCodes = from attr in attrs orderby attr.Category,attr.Code select attr;
            _needAuth = needAuth;
        }
Ejemplo n.º 2
0
 private void ScanParamDocumentation(TypeDescriptor typeDescriptor)
 {
     if (!typeDescriptor.Def.IsLeaf && typeDescriptor.Properties != null)
     {
         foreach (var property in typeDescriptor.Properties)
         {
             ScanPropertyDocumentation(property);
         }
     }
 }
Ejemplo n.º 3
0
        public void ScanTypeDefinition(HashSet<Type> parentCustomTypes)
        {
            _def = Container.GetOrCreate(_type);
            if (_def.IsObject)
            {
                var properties = _type.GetProperties();
                _properties = new List<PropertyDescriptor>(properties.Length);
                _propertiesDic = new Dictionary<string, PropertyDescriptor>(properties.Length, StringComparer.CurrentCultureIgnoreCase);

                if (_def.IsCustomObject)
                {
                    if (parentCustomTypes.Contains(_type)) return;
                    parentCustomTypes.Add(_type);
                }
                if (!TypeDefinition.IsDictionaryType(_type))
                {
                    foreach (var property in properties)
                    {
                        if (property.GetCustomAttributes(typeof(JsonIgnoreAttribute), false).Length > 0) continue;
                        var item = new PropertyDescriptor(property, _depth + 1);
                        item.Container = Container;
                        _properties.Add(item);
                        _propertiesDic.Add(property.Name, item);
                        item.ScanTypeDefinition(new HashSet<Type>(parentCustomTypes));
                    }
                }
            }
            else if (_def.IsArray && _def.SubType != null)
            {
                var subDef = Container.GetOrCreate(_def.SubType);
                _subType = new TypeDescriptor(_def.SubType.Name, _def.SubType, _depth);
                _subType.Container = Container;
                _subType.ScanTypeDefinition(parentCustomTypes);
            }
        }