小编Mat*_*ard的帖子

更新到后抛出CA1062!参数空值检查

根据 CA1062,外部可见方法中需要进行 null 检查,如下所示:

public static double GetLongitude(this Location location)
{
    if(location is null)
    {
        throw new ArgumentNullException(nameof(location));
    }

    return location.Longitude;
}
Run Code Online (Sandbox Code Playgroud)

我现在已经更新到.net 6.0并尝试使用参数null检查“!!”:

public static double GetLongitude(this Location location!!) => location.Longitude;
Run Code Online (Sandbox Code Playgroud)

但这又抛出了CA1062。

希望你们能帮助我:-)

c# visual-studio .net-6.0 c#-10.0 c#-11.0

10
推荐指数
1
解决办法
3220
查看次数

如何使用最小的 api .net 6 对端点进行排序

我正在尝试以最小的 API 掌握 swagger 的窍门。我有以下代码:

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(setup => setup.SwaggerDoc("v1", new OpenApiInfo()
{
    Description = "An api that will change your life for ever",
    Title = "Alert Api",
    Version = "v1",
    Contact = new OpenApiContact()
    {
        Name = "Grundfos",
        Url = new Uri("https://grundfos.com")
    }
}));
WebApplication app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

//Map endpoints
app.MapGet("/alerts", async () => Results.Ok());
app.MapGet("/profiles", async () => Results.Ok());
Run Code Online (Sandbox Code Playgroud)

这给出了一个看起来像这样的 swagger UI:

招摇界面

我的问题是:如何将端点排序到名为“警报”和“配置文件”的标题下?

swagger .net-6.0 minimal-apis

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

标签 统计

.net-6.0 ×2

c# ×1

c#-10.0 ×1

c#-11.0 ×1

minimal-apis ×1

swagger ×1

visual-studio ×1