小编Max*_*man的帖子

HashSet中的Union vs Unionwith

当我组合2个哈希集时,HashSet.Union vs 之间的区别是什么 HashSet.Unionwith.

我想这样组合:

HashSet<EngineType> enginesSupportAll = _filePolicyEvaluation.EnginesSupportAll;
        enginesSupportAll = enginesSupportAll != null ? new HashSet<EngineType>(engines.Union(enginesSupportAll)) : enginesSupportAll;
Run Code Online (Sandbox Code Playgroud)

这个例子的最佳方法是什么?为什么?

c# hashset

12
推荐指数
2
解决办法
9472
查看次数

使swashbuckle中的参数可选(不是必需的)

我想在我的控制器中将param作为可选项,但是swagger根据需要显示它.

我的控制器看起来像:

[HttpGet("{name}")]
[SwaggerResponse((int)HttpStatusCode.OK)]
[SwaggerResponse((int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> GetPolicy(string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         return BadRequest("Name is empty");
     }
     try
     {
         CRUDPolicyResponse crudPolicyResponse = await _managementOperations.CRUDPolicy(CRUDType.Read, name, null);
         if (!crudPolicyResponse.OperationSucceeded)
         {     
            return StatusCode((int)HttpStatusCode.BadRequest, crudPolicyResponse.Message);
         }
         if (crudPolicyResponse.FileMetadataPolicy == null)
         {
             return NotFound($"Policy name doesn't exists NAME: {name}");
         }
         return Ok(crudPolicyResponse.FileMetadataPolicy);
     }
     catch (Exception ex)
     {
        _log.Error("Error while trying to save file meta data policy", ex);
            return StatusCode((int)HttpStatusCode.InternalServerError, ex);
     }
 }
Run Code Online (Sandbox Code Playgroud)

我试图像这样更改为默认值:string name = null但不工作/ swashbuckle看起来像这样

所以名称字符串是必需的,我不能使用名称为空.

我试图通过这个解决方案来解决我的问题, 使得int可以为空

swagger asp.net-core

9
推荐指数
1
解决办法
4027
查看次数

标签 统计

asp.net-core ×1

c# ×1

hashset ×1

swagger ×1