.net8.0
This commit is contained in:
2
Models/Binder/.editorconfig
Normal file
2
Models/Binder/.editorconfig
Normal file
@ -0,0 +1,2 @@
|
||||
[*.cs]
|
||||
csharp_preserve_single_line_statements = true
|
@ -1,5 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WinLog.Models.Binder;
|
||||
|
||||
@ -21,29 +22,21 @@ 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;
|
||||
}
|
||||
|
||||
private static Models.AppSettings Get(AppSettings appSettings)
|
||||
private static Models.AppSettings Get(AppSettings? appSettings)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
if (appSettings.DateFormat is null)
|
||||
throw new NullReferenceException(nameof(DateFormat));
|
||||
if (appSettings.Directory is null)
|
||||
throw new NullReferenceException(nameof(Directory));
|
||||
if (appSettings.LogFilter is null)
|
||||
throw new NullReferenceException(nameof(LogFilter));
|
||||
if (appSettings.MessageFilters is null)
|
||||
throw new NullReferenceException(nameof(MessageFilters));
|
||||
if (appSettings.MillisecondsDelay is null)
|
||||
throw new NullReferenceException(nameof(MillisecondsDelay));
|
||||
if (appSettings.MonitorApplicationResource is null)
|
||||
throw new NullReferenceException(nameof(MonitorApplicationResource));
|
||||
if (appSettings.MonitorApplicationSite is null)
|
||||
throw new NullReferenceException(nameof(MonitorApplicationSite));
|
||||
if (appSettings.RollingMinutes is null)
|
||||
throw new NullReferenceException(nameof(RollingMinutes));
|
||||
if (appSettings?.DateFormat is null) throw new NullReferenceException(nameof(DateFormat));
|
||||
if (appSettings?.Directory is null) throw new NullReferenceException(nameof(Directory));
|
||||
if (appSettings?.LogFilter is null) throw new NullReferenceException(nameof(LogFilter));
|
||||
if (appSettings?.MessageFilters is null) throw new NullReferenceException(nameof(MessageFilters));
|
||||
if (appSettings?.MillisecondsDelay is null) throw new NullReferenceException(nameof(MillisecondsDelay));
|
||||
if (appSettings?.MonitorApplicationResource is null) throw new NullReferenceException(nameof(MonitorApplicationResource));
|
||||
if (appSettings?.MonitorApplicationSite is null) throw new NullReferenceException(nameof(MonitorApplicationSite));
|
||||
if (appSettings?.RollingMinutes is null) throw new NullReferenceException(nameof(RollingMinutes));
|
||||
result = new(appSettings.DateFormat, appSettings.Directory, appSettings.LogFilter, appSettings.MessageFilters, appSettings.MonitorApplicationResource, appSettings.MonitorApplicationSite, appSettings.MillisecondsDelay.Value, appSettings.RollingMinutes.Value);
|
||||
return result;
|
||||
}
|
||||
@ -51,9 +44,17 @@ public class AppSettings
|
||||
public static Models.AppSettings Get(IConfiguration configuration)
|
||||
{
|
||||
Models.AppSettings result;
|
||||
AppSettings appSettings = configuration.Get<AppSettings>();
|
||||
#pragma warning disable IL3050, IL2026
|
||||
AppSettings? appSettings = configuration.Get<AppSettings>();
|
||||
#pragma warning restore IL3050, IL2026
|
||||
result = Get(appSettings);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(AppSettings))]
|
||||
internal partial class BinderAppSettingsSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user