根据 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。
希望你们能帮助我:-)
我正在尝试以最小的 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:
我的问题是:如何将端点排序到名为“警报”和“配置文件”的标题下?