當前位置: 首頁>>代碼示例>>C#>>正文


C# Description.ApiParameterDescription類代碼示例

本文整理匯總了C#中System.Web.Http.Description.ApiParameterDescription的典型用法代碼示例。如果您正苦於以下問題:C# ApiParameterDescription類的具體用法?C# ApiParameterDescription怎麽用?C# ApiParameterDescription使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ApiParameterDescription類屬於System.Web.Http.Description命名空間,在下文中一共展示了ApiParameterDescription類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateParameter

        public ApiParameter CreateParameter(ApiParameterDescription parameterDescription, string relativePath)
        {
            var trueParamType = parameterDescription.ParameterDescriptor.ParameterType;

            var paramType = GetParamType(parameterDescription, relativePath);
            var isRequired = !parameterDescription.ParameterDescriptor.IsOptional;
            var dataType =  GetFriendlyTypeName(trueParamType);
            var allowMuliple = GetAllowMuliple(trueParamType);

            if (parameterDescription.ParameterDescriptor.ParameterType.IsEnum)
            {
                var possibleValues = new AllowableValues(trueParamType);
                return new ApiEnumParameter()
                {
                    name = parameterDescription.Name,
                    dataType = dataType,
                    paramType = paramType.ToString(),
                    description = parameterDescription.Documentation,
                    allowMultiple = allowMuliple,
                    required = isRequired,
                    allowableValues = possibleValues
                };        
            }

            return  new ApiParameter()
                          {
                              name = parameterDescription.Name,
                              dataType = dataType,
                              paramType = paramType.ToString(),
                              description = parameterDescription.Documentation,
                              allowMultiple = allowMuliple,
                              required = isRequired
                          };
        }
開發者ID:antonsamarsky,項目名稱:Swagger.Net,代碼行數:34,代碼來源:ParameterFactory.cs

示例2: GetParamType

 private static ParamType GetParamType(ApiParameterDescription parameterDescription, string relativePath)
 {
     var paramType = ParamType.body;
     if (parameterDescription.Source == ApiParameterSource.FromUri)
     {
         paramType = relativePath.IndexOf("{" + parameterDescription.Name + "}") > -1 ? ParamType.path :  ParamType.query;
     }
     return paramType;
 }
開發者ID:antonsamarsky,項目名稱:Swagger.Net,代碼行數:9,代碼來源:ParameterFactory.cs

示例3: CreateParameter

        public static ApiParameterDescription CreateParameter(string name, Type type, bool isOptional, ApiParameterSource source)
        {
            var p = MockRepository.GenerateStub<HttpParameterDescriptor>();
            p.Stub(x => x.ParameterName).Return(name);
            p.Stub(x => x.ParameterType).Return(type);
            p.Stub(x => x.IsOptional).Return(isOptional);

            var apiParam = new ApiParameterDescription() { ParameterDescriptor = p, Name = name, Source = source, Documentation = "yada" };
            return apiParam;
        }
開發者ID:danieleli,項目名稱:Swagger.Net,代碼行數:10,代碼來源:TestHelper.cs

示例4: CreateParameter

 /// <summary>
 /// Creates an operation parameter
 /// </summary>
 /// <param name="param">Description of a parameter on an operation via the ApiExplorer</param>
 /// <returns>An operation parameter</returns>
 public Parameter CreateParameter(ApiParameterDescription param)
 {
     var returnType = param.ParameterDescriptor.ParameterType.GetSwaggerType();
     return new Parameter()
     {
         ParamTypeEnum = param.GetParamType(),
         Name = param.Name,
         Description = param.Documentation,
         Type = returnType.Type,
         Format = returnType.Format,
         Enum = returnType.Enum,
         Required = !param.ParameterDescriptor.IsOptional,
         Items = param.ParameterDescriptor.ParameterType.IsIEnumerable() ? new Items{ Type = "string" } : null 
     };
 }
開發者ID:Tom-Kennedy,項目名稱:Swagger.Net,代碼行數:20,代碼來源:SwaggerGen.cs

示例5: GetBindableProperties_WorksOnlyFor_PublicInstanceProperties_WithPublicGettersAndSetters

        public void GetBindableProperties_WorksOnlyFor_PublicInstanceProperties_WithPublicGettersAndSetters()
        {
            // Arrange
            ApiParameterDescription parameter = new ApiParameterDescription();
            Mock<HttpParameterDescriptor> parameterDescriptorMock = new Mock<HttpParameterDescriptor>();
            parameterDescriptorMock.SetupGet(p => p.ParameterType).Returns(typeof(ClassWithAllKindsOfProperties));
            parameter.ParameterDescriptor = parameterDescriptorMock.Object;

            // Act
            IEnumerable<PropertyInfo> bindableProperties = parameter.GetBindableProperties();

            // Assert
            Assert.Equal(1, bindableProperties.Count());
            Assert.Equal("ValidProperty", bindableProperties.Single().Name);
        }
開發者ID:huangw-t,項目名稱:aspnetwebstack,代碼行數:15,代碼來源:ApiParameterDescriptionTest.cs

示例6: CreateParameter

        private Parameter CreateParameter(ApiParameterDescription apiParamDesc, string apiPath)
        {
            var paramType = "";
            switch (apiParamDesc.Source)
            {
                case ApiParameterSource.FromBody:
                    paramType = "body";
                    break;

                case ApiParameterSource.FromUri:
                    paramType = apiPath.Contains(String.Format("{{{0}}}", apiParamDesc.Name)) ? "path" : "query";
                    break;
            }

            if (apiParamDesc.ParameterDescriptor == null)
            {
                return new Parameter { ParamType = paramType, Name = apiParamDesc.Name, Required = true, Type = "string" };
            }

            var parameter = new Parameter
            {
                ParamType = paramType,
                Name = apiParamDesc.Name,
                Description = apiParamDesc.Documentation,
                Required = !apiParamDesc.ParameterDescriptor.IsOptional
            };

            var dataType = _dataTypeRegistry.GetOrRegister(apiParamDesc.ParameterDescriptor.ParameterType);
            if (dataType.Type == "object")
            {
                parameter.Type = dataType.Id;
            }
            else
            {
                parameter.Type = dataType.Type;
                parameter.Format = dataType.Format;
                parameter.Items = dataType.Items;
                parameter.Enum = dataType.Enum;
            }

            return parameter;
        }
開發者ID:AnthonyNeace,項目名稱:Swashbuckle,代碼行數:42,代碼來源:OperationGenerator.cs

示例7: CreateParameter

        private Parameter CreateParameter(ApiParameterDescription apiParamDesc, string apiPath, Dictionary<string, DataType> complexModels)
        {
            var paramType = "";
            switch (apiParamDesc.Source)
            {
                case ApiParameterSource.FromBody:
                    paramType = "body";
                    break;
                case ApiParameterSource.FromUri:
                    paramType = apiPath.Contains(String.Format("{{{0}}}", apiParamDesc.Name)) ? "path" : "query";
                    break;
            }

            var parameter = new Parameter
            {
                ParamType = paramType,
                Name = apiParamDesc.Name,
                Description = apiParamDesc.Documentation,
                Required = !apiParamDesc.ParameterDescriptor.IsOptional
            };

            IDictionary<string, DataType> complexModelsForParameter;
            var dataType = _dataTypeGenerator.TypeToDataType(apiParamDesc.ParameterDescriptor.ParameterType, out complexModelsForParameter);

            complexModels.Merge(complexModelsForParameter);

            if (dataType.Type == "object")
            {
                parameter.Type = dataType.Id;
            }
            else
            {
                parameter.Type = dataType.Type;
                parameter.Format = dataType.Format;
                parameter.Items = dataType.Items;
                parameter.Enum = dataType.Enum;
            }

            return parameter;
        }
開發者ID:kevynb,項目名稱:Swashbuckle,代碼行數:40,代碼來源:OperationGenerator.cs

示例8: BuildArguments

        private static string BuildArguments(ApiParameterDescription[] parameters)
        {
            if(parameters == null || parameters.Length == 0)
            {
                return string.Empty;
            }

            StringBuilder sb = new StringBuilder();

            int i = 0;
            foreach(var p in parameters)
            {
                sb.Append(p.Name);
                if(i!= parameters.Length-1)
                {
                    sb.Append(",");
                }
                i += 1;
            }

            return sb.ToString();
        }
開發者ID:BinRelease,項目名稱:SlashGetNet,代碼行數:22,代碼來源:AngularScriptManager.cs

示例9: CreateParameterSpec

        private ParameterSpec CreateParameterSpec(ApiParameterDescription apiParamDesc, string apiPath, ModelSpecRegistrar modelSpecRegistrar)
        {
            var paramType = "";
            switch (apiParamDesc.Source)
            {
                case ApiParameterSource.FromBody:
                    paramType = "body";
                    break;
                case ApiParameterSource.FromUri:
                    paramType = apiPath.Contains(apiParamDesc.Name) ? "path" : "query";
                    break;
            }

            var paramSpec = new ParameterSpec
            {
                ParamType = paramType,
                Name = apiParamDesc.Name,
                Description = apiParamDesc.Documentation,
                Required = !apiParamDesc.ParameterDescriptor.IsOptional
            };

            var modelSpec = _modelSpecGenerator.From(apiParamDesc.ParameterDescriptor.ParameterType, modelSpecRegistrar);

            if (modelSpec.Type == "object")
            {
                paramSpec.Type = modelSpec.Id;
            }
            else
            {
                paramSpec.Type = modelSpec.Type;
                paramSpec.Format = modelSpec.Format;
                paramSpec.Items = modelSpec.Items;
                paramSpec.Enum = modelSpec.Enum;
            }

            return paramSpec;
        }
開發者ID:robinvanderknaap,項目名稱:Swashbuckle.Lite,代碼行數:37,代碼來源:OperationSpecGenerator.cs

示例10: CreateResourceApiOperationParameter

        /// <summary>
        /// Creates an operation parameter
        /// </summary>
        /// <param name="api">Description of the api via the ApiExplorer</param>
        /// <param name="param">Description of a parameter on an operation via the ApiExplorer</param>
        /// <param name="docProvider">Access to the XML docs written in code</param>
        /// <returns>An operation parameter</returns>
        public static ResourceApiOperationParameter CreateResourceApiOperationParameter(ApiDescription api, ApiParameterDescription param, XmlCommentDocumentationProvider docProvider)
        {
            string paramType = (param.Source.ToString().Equals(FROMURI)) ? QUERY : BODY;
            ResourceApiOperationParameter parameter = new ResourceApiOperationParameter()
            {
                paramType = (paramType == "query" && api.RelativePath.IndexOf("{" + param.Name + "}") > -1) ? PATH : paramType,
                name = param.Name,
                description = param.Documentation,
                dataType = param.ParameterDescriptor.ParameterType.Name,
                required = docProvider.GetRequired(param.ParameterDescriptor)
            };

            return parameter;
        }
開發者ID:DveMac,項目名稱:Swagger.Net,代碼行數:21,代碼來源:SwaggerModels.cs

示例11: AddParameterDescription

        public static ParameterDescription AddParameterDescription(
            this Collection<ParameterDescription> uriParameters,
            ApiParameterDescription apiParameter, ModelDescription typeDescription)
        {
            var parameterDescription = new ParameterDescription
            {
                Name = apiParameter.Name,
                Documentation = apiParameter.Documentation,
                TypeDescription = typeDescription,
            };

            uriParameters.Add(parameterDescription);
            return parameterDescription;
        }
開發者ID:ouyh18,項目名稱:LtePlatform,代碼行數:14,代碼來源:HelpPageConfigurationExtensions.cs

示例12: GetParameterLocation

 private string GetParameterLocation(ApiDescription apiDesc, ApiParameterDescription paramDesc)
 {
     if (apiDesc.RelativePathSansQueryString().Contains("{" + paramDesc.Name + "}"))
         return "path";
     else if (paramDesc.Source == ApiParameterSource.FromBody && apiDesc.HttpMethod != HttpMethod.Get)
         return "body";
     else
         return "query";
 }
開發者ID:sk8tz,項目名稱:Swashbuckle,代碼行數:9,代碼來源:SwaggerGenerator.cs

示例13: GenerateParameterSpec

        private ParameterSpec GenerateParameterSpec(ApiParameterDescription parameterDescription, string apiPath, ModelSpecMap modelSpecMap)
        {
            var paramType = "";
            switch (parameterDescription.Source)
            {
                case ApiParameterSource.FromBody:
                    paramType = "body";
                    break;
                case ApiParameterSource.FromUri:
                    paramType = apiPath.Contains(parameterDescription.Name) ? "path" : "query";
                    break;
            }

            var paramSpec = new ParameterSpec
            {
                ParamType = paramType,
                Name = parameterDescription.Name,
                Description = parameterDescription.Documentation,
                Required = !parameterDescription.ParameterDescriptor.IsOptional
            };

            var modelSpec = modelSpecMap.FindOrCreateFor(parameterDescription.ParameterDescriptor.ParameterType);
            if (modelSpec.Type == "object")
            {
                paramSpec.Type = modelSpec.Id;
            }
            else
            {
                paramSpec.Type = modelSpec.Type;
                paramSpec.Format = modelSpec.Format;
                paramSpec.Items = modelSpec.Items;
                paramSpec.Enum = modelSpec.Enum;
            }

            return paramSpec;
        }
開發者ID:nprovencher,項目名稱:Swashbuckle,代碼行數:36,代碼來源:SwaggerGenerator.cs

示例14: CreateResourceModel

 public static IList<ResourceModelNode> CreateResourceModel(ApiParameterDescription param, XmlCommentDocumentationProvider docProvider)
 {
     return CreateResourceModel(param, param.ParameterDescriptor.ParameterType, docProvider);
 }
開發者ID:giacomelli,項目名稱:DG-Swagger.Net,代碼行數:4,代碼來源:SwaggerModels.cs

示例15: CreateParameter

        private Parameter CreateParameter(string location, ApiParameterDescription paramDesc, SchemaRegistry schemaRegistry)
        {
            var parameter = new Parameter
            {
                @in = location,
                name = paramDesc.Name
            };

            if (paramDesc.ParameterDescriptor == null)
            {
                parameter.type = "string";
                parameter.required = true;
                return parameter;
            }

            parameter.required = location == "path" || !paramDesc.ParameterDescriptor.IsOptional;
            [email protected] = paramDesc.ParameterDescriptor.DefaultValue;

            var schema = schemaRegistry.GetOrRegister(paramDesc.ParameterDescriptor.ParameterType);
            if ([email protected] == "body")
                parameter.schema = schema;
            else
                parameter.PopulateFrom(schema);

            return parameter;
        }
開發者ID:sk8tz,項目名稱:Swashbuckle,代碼行數:26,代碼來源:SwaggerGenerator.cs


注:本文中的System.Web.Http.Description.ApiParameterDescription類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。