Adopt C# 12 collection expressions for empty lists/dicts
Refactored code to use C# 12 collection expressions ([]) for initializing empty lists and dictionaries instead of the older constructors. This change modernizes and simplifies collection initialization across models, services, and API clients without altering any logic.
This commit is contained in:
@@ -88,9 +88,9 @@ namespace DbFirst.BlazorWebApp.Services
|
||||
Dictionary<string, ColumnDefinition> columnLookup)
|
||||
{
|
||||
layout ??= new BandLayout();
|
||||
layout.Bands ??= new List<BandDefinition>();
|
||||
layout.ColumnOrder ??= new List<string>();
|
||||
layout.ColumnWidths ??= new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
|
||||
layout.Bands ??= [];
|
||||
layout.ColumnOrder ??= [];
|
||||
layout.ColumnWidths ??= [];
|
||||
|
||||
foreach (var band in layout.Bands)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ public class CatalogApiClient : ICatalogApiClient
|
||||
public async Task<List<CatalogReadDto>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
var result = await _httpClient.GetFromJsonAsync<List<CatalogReadDto>>(Endpoint, ct);
|
||||
return result ?? new List<CatalogReadDto>();
|
||||
return result ?? [];
|
||||
}
|
||||
|
||||
public async Task<CatalogReadDto?> GetByIdAsync(int id, CancellationToken ct = default)
|
||||
|
||||
@@ -16,6 +16,6 @@ public class DashboardApiClient : IDashboardApiClient
|
||||
public async Task<List<DashboardInfoDto>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
var result = await _httpClient.GetFromJsonAsync<List<DashboardInfoDto>>(Endpoint, ct);
|
||||
return result ?? new List<DashboardInfoDto>();
|
||||
return result ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class MassDataApiClient : IMassDataApiClient
|
||||
|
||||
var url = query.Count == 0 ? Endpoint : $"{Endpoint}?{string.Join("&", query)}";
|
||||
var result = await _httpClient.GetFromJsonAsync<List<MassDataReadDto>>(url, ct);
|
||||
return result ?? new List<MassDataReadDto>();
|
||||
return result ?? [];
|
||||
}
|
||||
|
||||
public async Task<ApiResult<MassDataReadDto?>> UpsertAsync(MassDataWriteDto dto, CancellationToken ct = default)
|
||||
|
||||
Reference in New Issue
Block a user