private record
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
using File_Folder_Helper.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
@ -10,6 +9,29 @@ namespace File_Folder_Helper.ADO2024.PI1;
|
||||
internal static partial class Helper20240106
|
||||
{
|
||||
|
||||
private record Host([property: JsonPropertyName("a")] string? Id,
|
||||
[property: JsonPropertyName("b")] string? Colon,
|
||||
[property: JsonPropertyName("c")] string? Hyphen,
|
||||
[property: JsonPropertyName("d")] string? Line,
|
||||
[property: JsonPropertyName("e")] string? Count,
|
||||
[property: JsonPropertyName("f")] string? Segments,
|
||||
[property: JsonPropertyName("g")] string? Type,
|
||||
[property: JsonPropertyName("h")] string? Device,
|
||||
[property: JsonPropertyName("i")] string? Name,
|
||||
[property: JsonPropertyName("j")] string? Location);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, AllowTrailingCommas = true)]
|
||||
[JsonSerializable(typeof(Host[]))]
|
||||
private partial class HostCollectionSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Dictionary<string, Dictionary<string, string>>))]
|
||||
private partial class DictionaryDictionarySourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
private record Record(string Key, Dictionary<string, string> KeyValuePairs);
|
||||
|
||||
private static Dictionary<string, Dictionary<string, string>> GetKeyValuePairs(List<Record> collection, bool replaceFound)
|
||||
@ -33,7 +55,7 @@ internal static partial class Helper20240106
|
||||
Dictionary<int, Host> results = [];
|
||||
int id;
|
||||
string json = $"[{File.ReadAllText(jsonl).Replace("\r\n", ",")}]";
|
||||
Host[] hosts = JsonSerializer.Deserialize(json, HostSourceGenerationContext.Default.HostArray) ?? throw new NullReferenceException(nameof(json));
|
||||
Host[] hosts = JsonSerializer.Deserialize(json, HostCollectionSourceGenerationContext.Default.HostArray) ?? throw new NullReferenceException(nameof(json));
|
||||
foreach (Host host in hosts)
|
||||
{
|
||||
if (host.Id is null)
|
||||
@ -182,12 +204,6 @@ internal static partial class Helper20240106
|
||||
File.AppendAllLines(hostConfFile, lines);
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Dictionary<string, Dictionary<string, string>>))]
|
||||
private partial class DictionaryDictionarySourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
internal static void TextToJson(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
string json;
|
||||
|
@ -7,7 +7,7 @@ namespace File_Folder_Helper.ADO2024.PI1;
|
||||
internal static partial class Helper20240409
|
||||
{
|
||||
|
||||
internal record FsSize( // cSpell:disable
|
||||
private record FsSize( // cSpell:disable
|
||||
[property: JsonPropertyName("name")] string Name,
|
||||
[property: JsonPropertyName("object")] string Object,
|
||||
[property: JsonPropertyName("pmon")] string PMon,
|
||||
@ -19,7 +19,7 @@ internal static partial class Helper20240409
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, AllowTrailingCommas = true)]
|
||||
[JsonSerializable(typeof(FsSize))]
|
||||
internal partial class FsSizeSourceGenerationContext : JsonSerializerContext
|
||||
private partial class FsSizeSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ namespace File_Folder_Helper.ADO2024.PI1;
|
||||
internal static partial class Helper20240427
|
||||
{
|
||||
|
||||
internal record Asset( // cSpell:disable
|
||||
private record Asset( // cSpell:disable
|
||||
[property: JsonPropertyName("id")] string? Id,
|
||||
[property: JsonPropertyName("deviceAssetId")] string? DeviceAssetId,
|
||||
[property: JsonPropertyName("ownerId")] string? OwnerId,
|
||||
@ -42,7 +42,7 @@ internal static partial class Helper20240427
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, AllowTrailingCommas = true)]
|
||||
[JsonSerializable(typeof(List<Asset>))]
|
||||
internal partial class AssetCollectionSourceGenerationContext : JsonSerializerContext
|
||||
private partial class AssetCollectionSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user