小编Nic*_*ico的帖子

Swagger 为 ASP.CORE 3 中的字典生成错误的 URL

当从查询字符串中提取的模型将字典作为其属性之一时,Swagger 会生成错误的 URL。如何告诉 Swagger 更改 URL 中字典的格式或手动定义输入参数架构,而不自动生成?尝试使用 Swashbuckle 和 NSwag。

控制器

public class RecordsController : ControllerBase
{
  [HttpGet]
  [Route("services/records")]
  public async Task<IActionResult> Records([FromQuery] QueryModel queryModel)
  {
    return null;
  }
}
Run Code Online (Sandbox Code Playgroud)

输入模型 - 查询字符串

public class QueryModel 
{
  public int Page { get; set; }
  public int Count { get; set; }
  public Dictionary<Columns, string> Conditions { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

Swagger UI为查询模型上的“条件”属性显示了这种格式

{
  "UserId": "string",
  "GroupId": "string",
  "RecordId": "string"
}
Run Code Online (Sandbox Code Playgroud)

Swagger 生成的 URL - Open API v2 - 不会绑定到“条件” …

swagger swashbuckle asp.net-core asp.net-core-webapi swashbuckle.aspnetcore

5
推荐指数
1
解决办法
1023
查看次数

ConcurrentDictionary 和 ImmutableDictionary 之间有什么区别?

我正在阅读C# Cookbook 中的并发,这本书告诉我:

ConcurrentDictionary<TKey, TValue>当您有多个线程读取和写入共享集合时,这是最好的。如果更新不是恒定的(如果它们更罕见),那么这ImmutableDictionary<TKey,TValue> 可能是一个更好的选择。

我知道 Add or Remove a large immutable collection 可能很慢,我的问题是,它们之间还有其他区别吗?既然它们都是线程安全的,那么ImmutableDictionary当更新不是恒定的时,为什么是更好的选择呢?

.net c# multithreading dictionary

3
推荐指数
1
解决办法
2193
查看次数