예제 #1
0
        private static ApiParameter MakeParameter(Type type)
        {
            Type actualType = type.ListedType() ?? type.DictionariedType() ?? type;

            actualType = Nullable.GetUnderlyingType(actualType) ?? actualType;
            _typeCache[actualType.FullName] = actualType;
            var p = new ApiParameter()
            {
                TypeName     = actualType.FullName,
                IsDictionary = type.IsDictionary(),
                IsList       = type.ListedType() != null,
                IsSimple     = actualType.IsSimpleType()
            };

            if (p.IsDictionary)
            {
                p.TypeName = null;

                if (type.GenericTypeArguments.Length == 2)
                {
                    p.KeyTypeName   = type.GenericTypeArguments[0].FullName;
                    p.ValueTypeName = type.GenericTypeArguments[1].FullName;
                }
            }

            return(p);
        }
예제 #2
0
        private static List <ComplexType> GetComplexTypes(ApiParameter param)
        {
            List <ComplexType> types = new List <ComplexType>();

            AddToComplexTypesList(types, param);

            return(types);
        }
예제 #3
0
        private static ApiParameter MakeParameter(ApiParameterDescription apd)
        {
            Type         ptype = apd.ParameterDescriptor.ParameterType;
            ApiParameter p     = MakeParameter(ptype);

            p.Name = apd.Name;
            return(p);
        }
예제 #4
0
        private static void AddToComplexTypesList(List <ComplexType> list, ApiParameter param)
        {
            if (param != null)
            {
                string typeName = param.TypeName ?? param.ValueTypeName;
                if (!list.Any(c => c.Name == typeName) && !param.IsSimple)
                {
                    Type        type = _typeCache[typeName];
                    ComplexType ct   = new ComplexType();
                    list.Add(ct);
                    ct.Name       = type.FullName;
                    ct.Properties = new List <ApiParameter>();
                    PropertyInfo[] propertyInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                    foreach (var pi in propertyInfos)
                    {
                        ApiParameter prop = MakeParameter(pi.PropertyType);
                        prop.Name = pi.Name;
                        ct.Properties.Add(prop);

                        AddToComplexTypesList(list, prop);
                    }
                }
            }
        }
예제 #5
0
        private static List <ApiParameter> GetQueryParameters(ApiDescription desc)
        {
            List <ApiParameter> apiParameters = new List <ApiParameter>();

            foreach (ApiParameterDescription apd in desc.ParameterDescriptions.Where(d => d.Source == ApiParameterSource.FromUri &&
                                                                                     desc.Route.RouteTemplate.IndexOf("{" + d.Name + "}",
                                                                                                                      StringComparison.InvariantCultureIgnoreCase) < 0))
            {
                ApiParameter ap = MakeParameter(apd);
                if (ap.IsSimple)
                {
                    apiParameters.Add(ap);
                }
                else
                {
                    ComplexType ct = GetComplexTypes(ap).First();
                    apiParameters.AddRange(ct.Properties);
                }
            }



            return(apiParameters);
        }