SourceGenerationContext
This commit is contained in:
parent
229b508ae1
commit
22797ad4bf
@ -609,10 +609,15 @@ internal static partial class HelperMarkdown
|
|||||||
string directory = Path.Combine(Environment.CurrentDirectory, ".vscode");
|
string directory = Path.Combine(Environment.CurrentDirectory, ".vscode");
|
||||||
if (!Directory.Exists(directory))
|
if (!Directory.Exists(directory))
|
||||||
{
|
{
|
||||||
JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true };
|
string json;
|
||||||
string json = JsonSerializer.Serialize(collection.Select(l => l.MarkdownFile), jsonSerializerOptions);
|
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);
|
File.WriteAllText($"{DateTime.Now.Ticks}.json", json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,19 +1,11 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace File_Folder_Helper.Helpers;
|
namespace File_Folder_Helper.Helpers;
|
||||||
|
|
||||||
internal static class HelperPackageFilesByDate
|
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)
|
internal static void SetDateFromJsonEntry(ILogger log, string sourceDirectory, SearchOption searchOption = SearchOption.AllDirectories)
|
||||||
{
|
{
|
||||||
string json;
|
string json;
|
||||||
@ -40,7 +32,7 @@ internal static class HelperPackageFilesByDate
|
|||||||
if (string.IsNullOrEmpty(packageJsonDirectory))
|
if (string.IsNullOrEmpty(packageJsonDirectory))
|
||||||
continue;
|
continue;
|
||||||
json = File.ReadAllText(packageJsonFile);
|
json = File.ReadAllText(packageJsonFile);
|
||||||
packageJson = JsonSerializer.Deserialize<PackageJson>(json);
|
packageJson = JsonSerializer.Deserialize(json, PackageJsonSourceGenerationContext.Default.PackageJson);
|
||||||
if (packageJson is null || !packageJson.Times.Any())
|
if (packageJson is null || !packageJson.Times.Any())
|
||||||
continue;
|
continue;
|
||||||
packageJsonDirectoryName = Path.GetFileName(packageJsonDirectory);
|
packageJsonDirectoryName = Path.GetFileName(packageJsonDirectory);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace File_Folder_Helper.Helpers;
|
namespace File_Folder_Helper.Helpers;
|
||||||
|
|
||||||
public record LineNumber(int? Created,
|
public record LineNumber(int? Created,
|
||||||
@ -6,3 +8,9 @@ public record LineNumber(int? Created,
|
|||||||
int? Status,
|
int? Status,
|
||||||
int? Type,
|
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;
|
namespace File_Folder_Helper.Helpers;
|
||||||
|
|
||||||
public record MarkdownFile(string File,
|
public record MarkdownFile(string File,
|
||||||
@ -10,3 +12,15 @@ public record MarkdownFile(string File,
|
|||||||
LineNumber LineNumber,
|
LineNumber LineNumber,
|
||||||
string Type,
|
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;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace File_Folder_Helper.Models;
|
namespace File_Folder_Helper.Models;
|
||||||
|
|
||||||
@ -10,8 +11,14 @@ public record AppSettings(string Company,
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
string result = JsonSerializer.Serialize(this, AppSettingsSourceGenerationContext.Default.AppSettings);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
[JsonSerializable(typeof(AppSettings))]
|
||||||
|
internal partial class AppSettingsSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace File_Folder_Helper.Models.Binder;
|
namespace File_Folder_Helper.Models.Binder;
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ public class AppSettings
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
string result = JsonSerializer.Serialize(this, BinderAppSettingsSourceGenerationContext.Default.AppSettings);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,9 +41,17 @@ public class AppSettings
|
|||||||
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
|
||||||
{
|
{
|
||||||
Models.AppSettings result;
|
Models.AppSettings result;
|
||||||
|
#pragma warning disable IL3050, IL2026
|
||||||
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
|
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
|
||||||
|
#pragma warning restore IL3050, IL2026
|
||||||
result = Get(appSettings);
|
result = Get(appSettings);
|
||||||
return result;
|
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)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
#pragma warning disable IL3050
|
||||||
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
|
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
|
||||||
|
#pragma warning restore IL3050
|
||||||
_ = builder.Configuration.AddEnvironmentVariables();
|
_ = builder.Configuration.AddEnvironmentVariables();
|
||||||
_ = builder.Configuration.AddUserSecrets<Program>();
|
_ = builder.Configuration.AddUserSecrets<Program>();
|
||||||
_ = builder.Services.AddSingleton(args.ToList());
|
_ = builder.Services.AddSingleton(args.ToList());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user