SourceGenerationContext
This commit is contained in:
@ -609,9 +609,14 @@ internal static partial class HelperMarkdown
|
||||
string directory = Path.Combine(Environment.CurrentDirectory, ".vscode");
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true };
|
||||
string json = JsonSerializer.Serialize(collection.Select(l => l.MarkdownFile), jsonSerializerOptions);
|
||||
File.WriteAllText($"{DateTime.Now.Ticks}.json", json);
|
||||
string json;
|
||||
MarkdownFile markdownFile = collection.First().MarkdownFile;
|
||||
json = JsonSerializer.Serialize(markdownFile, MarkdownFileSourceGenerationContext.Default.MarkdownFile);
|
||||
if (json != "{}")
|
||||
{
|
||||
json = JsonSerializer.Serialize(collection.Select(l => l.MarkdownFile).ToArray(), MarkdownFileCollectionSourceGenerationContext.Default.MarkdownFileArray);
|
||||
File.WriteAllText($"{DateTime.Now.Ticks}.json", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,11 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static class HelperPackageFilesByDate
|
||||
{
|
||||
|
||||
public record PackageJson(
|
||||
[property: JsonPropertyName("name")] string Name,
|
||||
[property: JsonPropertyName("time")] Dictionary<string, DateTime> Times,
|
||||
[property: JsonPropertyName("_rev")] string Rev,
|
||||
[property: JsonPropertyName("_id")] string Id
|
||||
);
|
||||
|
||||
internal static void SetDateFromJsonEntry(ILogger log, string sourceDirectory, SearchOption searchOption = SearchOption.AllDirectories)
|
||||
{
|
||||
string json;
|
||||
@ -40,7 +32,7 @@ internal static class HelperPackageFilesByDate
|
||||
if (string.IsNullOrEmpty(packageJsonDirectory))
|
||||
continue;
|
||||
json = File.ReadAllText(packageJsonFile);
|
||||
packageJson = JsonSerializer.Deserialize<PackageJson>(json);
|
||||
packageJson = JsonSerializer.Deserialize(json, PackageJsonSourceGenerationContext.Default.PackageJson);
|
||||
if (packageJson is null || !packageJson.Times.Any())
|
||||
continue;
|
||||
packageJsonDirectoryName = Path.GetFileName(packageJsonDirectory);
|
||||
|
@ -1,3 +1,5 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
public record LineNumber(int? Created,
|
||||
@ -5,4 +7,10 @@ public record LineNumber(int? Created,
|
||||
int? MetaEnd,
|
||||
int? Status,
|
||||
int? Type,
|
||||
int? Updated);
|
||||
int? Updated);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(LineNumber))]
|
||||
internal partial class LineNumberSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
public record MarkdownFile(string File,
|
||||
@ -9,4 +11,16 @@ public record MarkdownFile(string File,
|
||||
DateTime LastWriteDateTime,
|
||||
LineNumber LineNumber,
|
||||
string Type,
|
||||
string H1);
|
||||
string H1);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(MarkdownFile))]
|
||||
internal partial class MarkdownFileSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(MarkdownFile[]))]
|
||||
internal partial class MarkdownFileCollectionSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
20
Helpers/PackageJson.cs
Normal file
20
Helpers/PackageJson.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
public record PackageJson([property: JsonPropertyName("name")] string Name,
|
||||
[property: JsonPropertyName("time")] Dictionary<string, DateTime> Times,
|
||||
[property: JsonPropertyName("_rev")] string Rev,
|
||||
[property: JsonPropertyName("_id")] string Id);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(PackageJson))]
|
||||
internal partial class PackageJsonSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(PackageJson[]))]
|
||||
internal partial class PackageJsonCollectionSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user