SourceGenerationContext
This commit is contained in:
parent
229b508ae1
commit
22797ad4bf
@ -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
|
||||
{
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace File_Folder_Helper.Models;
|
||||
|
||||
@ -10,8 +11,14 @@ public record AppSettings(string Company,
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
string result = JsonSerializer.Serialize(this, AppSettingsSourceGenerationContext.Default.AppSettings);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(AppSettings))]
|
||||
internal partial class AppSettingsSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace File_Folder_Helper.Models.Binder;
|
||||
|
||||
@ -13,7 +14,7 @@ public class AppSettings
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
string result = JsonSerializer.Serialize(this, BinderAppSettingsSourceGenerationContext.Default.AppSettings);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -40,9 +41,17 @@ public class AppSettings
|
||||
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
#pragma warning disable IL3050, IL2026
|
||||
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
|
||||
#pragma warning restore IL3050, IL2026
|
||||
result = Get(appSettings);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(AppSettings))]
|
||||
internal partial class BinderAppSettingsSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
@ -11,7 +11,9 @@ internal class Program
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
#pragma warning disable IL3050
|
||||
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
|
||||
#pragma warning restore IL3050
|
||||
_ = builder.Configuration.AddEnvironmentVariables();
|
||||
_ = builder.Configuration.AddUserSecrets<Program>();
|
||||
_ = builder.Services.AddSingleton(args.ToList());
|
||||
|
Loading…
x
Reference in New Issue
Block a user