Remove .Any

H2 Records
This commit is contained in:
2023-09-27 23:05:40 -07:00
parent 4ba2a42ed1
commit f810af3ebe
13 changed files with 307 additions and 61 deletions

View File

@ -0,0 +1,2 @@
[*.cs]
csharp_preserve_single_line_statements = true

View File

@ -25,22 +25,14 @@ public class AppSettings
private static Models.AppSettings Get(AppSettings? appSettings)
{
Models.AppSettings result;
if (appSettings?.Company is null)
throw new NullReferenceException(nameof(appSettings.Company));
if (appSettings?.DefaultNoteType is null)
throw new NullReferenceException(nameof(appSettings.DefaultNoteType));
if (appSettings?.ExcludeDirectoryNames is null)
throw new NullReferenceException(nameof(appSettings.ExcludeDirectoryNames));
if (appSettings?.ExcludeSchemes is null)
throw new NullReferenceException(nameof(appSettings.ExcludeSchemes));
if (appSettings?.PersonBirthdayFormat is null)
throw new NullReferenceException(nameof(appSettings.PersonBirthdayFormat));
if (appSettings?.PersonCharacters is null)
throw new NullReferenceException(nameof(appSettings.PersonCharacters));
if (appSettings?.PersonTitleFilters is null)
throw new NullReferenceException(nameof(appSettings.PersonTitleFilters));
if (appSettings?.WorkingDirectoryName is null)
throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
if (appSettings?.Company is null) throw new NullReferenceException(nameof(appSettings.Company));
if (appSettings?.DefaultNoteType is null) throw new NullReferenceException(nameof(appSettings.DefaultNoteType));
if (appSettings?.ExcludeDirectoryNames is null) throw new NullReferenceException(nameof(appSettings.ExcludeDirectoryNames));
if (appSettings?.ExcludeSchemes is null) throw new NullReferenceException(nameof(appSettings.ExcludeSchemes));
if (appSettings?.PersonBirthdayFormat is null) throw new NullReferenceException(nameof(appSettings.PersonBirthdayFormat));
if (appSettings?.PersonCharacters is null) throw new NullReferenceException(nameof(appSettings.PersonCharacters));
if (appSettings?.PersonTitleFilters is null) throw new NullReferenceException(nameof(appSettings.PersonTitleFilters));
if (appSettings?.WorkingDirectoryName is null) throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
result = new(
appSettings.Company,
appSettings.DefaultNoteType,
@ -60,6 +52,19 @@ public class AppSettings
#pragma warning disable IL3050, IL2026
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
#pragma warning restore IL3050, IL2026
if (appSettings?.Company is null)
{
foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers)
{
if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider)
continue;
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider)
continue;
if (!physicalFileProvider.Root.Contains("UserSecrets"))
continue;
throw new NotSupportedException(physicalFileProvider.Root);
}
}
result = Get(appSettings);
return result;
}

12
Models/H2HexColor.cs Normal file
View File

@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace File_Folder_Helper.Models;
internal record H2HexColor(string H2,
string HexColor);
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(H2HexColor))]
internal partial class H2PatternMatchesSourceGenerationContext : JsonSerializerContext
{
}

13
Models/H2NoCheckboxes.cs Normal file
View File

@ -0,0 +1,13 @@
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
namespace File_Folder_Helper.Models;
internal record H2NoCheckboxes(string H2,
ReadOnlyCollection<string> Lines);
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(H2NoCheckboxes))]
internal partial class H2NoCheckboxesSourceGenerationContext : JsonSerializerContext
{
}

View File

@ -0,0 +1,14 @@
using System.Text.Json.Serialization;
namespace File_Folder_Helper.Models;
internal record H2WithCheckboxes(int Completed,
string H2,
int NotCompleted,
int Total);
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(H2WithCheckboxes))]
internal partial class H2WithCheckboxesSourceGenerationContext : JsonSerializerContext
{
}

View File

@ -2,12 +2,12 @@ using System.Text.Json.Serialization;
namespace File_Folder_Helper.Models;
public record LineNumber(int? Created,
int? H1,
int? FrontMatterYamlEnd,
int? Status,
int? Type,
int? Updated);
internal record LineNumber(int? Created,
int? H1,
int? FrontMatterYamlEnd,
int? Status,
int? Type,
int? Updated);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(LineNumber))]

View File

@ -1,17 +1,23 @@
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
namespace File_Folder_Helper.Models;
public record MarkdownFile(string File,
string Directory,
string FileName,
string FileNameWithoutExtension,
string Extension,
DateTime CreationDateTime,
DateTime LastWriteDateTime,
LineNumber LineNumber,
string Type,
string H1);
internal record MarkdownFile(ReadOnlyCollection<string>? Assignees,
DateTime CreationDateTime,
string Directory,
string Extension,
string File,
string FileName,
string FileNameWithoutExtension,
string H1,
ReadOnlyCollection<H2HexColor>? H2HexColorCollection,
ReadOnlyCollection<H2NoCheckboxes>? H2NoCheckboxesCollection,
ReadOnlyCollection<H2WithCheckboxes>? H2WithCheckboxesCollection,
DateTime LastWriteDateTime,
LineNumber LineNumber,
string? RequestedDateTime,
string Type);
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(MarkdownFile))]