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:
@@ -162,7 +162,7 @@ public abstract class BandGridBase<TItem> : ComponentBase
|
|||||||
|
|
||||||
protected void UpdateBandOptions()
|
protected void UpdateBandOptions()
|
||||||
{
|
{
|
||||||
bandOptions = new List<BandOption> { new() { Id = string.Empty, Caption = "Ohne Band" } };
|
bandOptions = [new() { Id = string.Empty, Caption = "Ohne Band" }];
|
||||||
bandOptions.AddRange(bandLayout.Bands.Select(b => new BandOption { Id = b.Id, Caption = b.Caption }));
|
bandOptions.AddRange(bandLayout.Bands.Select(b => new BandOption { Id = b.Id, Caption = b.Caption }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ namespace DbFirst.BlazorWebApp.Models.Grid
|
|||||||
{
|
{
|
||||||
public class BandLayout
|
public class BandLayout
|
||||||
{
|
{
|
||||||
public List<BandDefinition> Bands { get; set; } = new();
|
public List<BandDefinition> Bands { get; set; } = [];
|
||||||
public List<string> ColumnOrder { get; set; } = new();
|
public List<string> ColumnOrder { get; set; } = [];
|
||||||
public Dictionary<string, string?> ColumnWidths { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
public Dictionary<string, string?> ColumnWidths { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||||
public GridPersistentLayout? GridLayout { get; set; }
|
public GridPersistentLayout? GridLayout { get; set; }
|
||||||
public SizeMode SizeMode { get; set; } = SizeMode.Medium;
|
public SizeMode SizeMode { get; set; } = SizeMode.Medium;
|
||||||
@@ -15,7 +15,7 @@ namespace DbFirst.BlazorWebApp.Models.Grid
|
|||||||
{
|
{
|
||||||
public string Id { get; set; } = string.Empty;
|
public string Id { get; set; } = string.Empty;
|
||||||
public string Caption { get; set; } = string.Empty;
|
public string Caption { get; set; } = string.Empty;
|
||||||
public List<string> Columns { get; set; } = new();
|
public List<string> Columns { get; set; } = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BandOption
|
public class BandOption
|
||||||
|
|||||||
@@ -88,9 +88,9 @@ namespace DbFirst.BlazorWebApp.Services
|
|||||||
Dictionary<string, ColumnDefinition> columnLookup)
|
Dictionary<string, ColumnDefinition> columnLookup)
|
||||||
{
|
{
|
||||||
layout ??= new BandLayout();
|
layout ??= new BandLayout();
|
||||||
layout.Bands ??= new List<BandDefinition>();
|
layout.Bands ??= [];
|
||||||
layout.ColumnOrder ??= new List<string>();
|
layout.ColumnOrder ??= [];
|
||||||
layout.ColumnWidths ??= new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
|
layout.ColumnWidths ??= [];
|
||||||
|
|
||||||
foreach (var band in layout.Bands)
|
foreach (var band in layout.Bands)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class CatalogApiClient : ICatalogApiClient
|
|||||||
public async Task<List<CatalogReadDto>> GetAllAsync(CancellationToken ct = default)
|
public async Task<List<CatalogReadDto>> GetAllAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
var result = await _httpClient.GetFromJsonAsync<List<CatalogReadDto>>(Endpoint, ct);
|
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)
|
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)
|
public async Task<List<DashboardInfoDto>> GetAllAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
var result = await _httpClient.GetFromJsonAsync<List<DashboardInfoDto>>(Endpoint, ct);
|
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 url = query.Count == 0 ? Endpoint : $"{Endpoint}?{string.Join("&", query)}";
|
||||||
var result = await _httpClient.GetFromJsonAsync<List<MassDataReadDto>>(url, ct);
|
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)
|
public async Task<ApiResult<MassDataReadDto?>> UpsertAsync(MassDataWriteDto dto, CancellationToken ct = default)
|
||||||
|
|||||||
Reference in New Issue
Block a user