feat: upgrade to .NET 6, refactor everything

This commit is contained in:
spiral
2021-11-26 21:10:56 -05:00
parent d28e99ba43
commit 1918c56937
314 changed files with 27954 additions and 27966 deletions

View File

@@ -1,30 +1,27 @@
using System.Collections.Generic;
using Serilog.Core;
using Serilog.Events;
namespace PluralKit.Core
namespace PluralKit.Core;
public class PatchObjectDestructuring: IDestructuringPolicy
{
public class PatchObjectDestructuring: IDestructuringPolicy
public bool TryDestructure(object value, ILogEventPropertyValueFactory factory,
out LogEventPropertyValue result)
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory factory,
out LogEventPropertyValue result)
result = null;
if (!(value is PatchObject po)) return false;
var propList = new List<LogEventProperty>();
foreach (var props in po.GetType().GetProperties())
{
result = null;
if (!(value is PatchObject po)) return false;
var propList = new List<LogEventProperty>();
foreach (var props in po.GetType().GetProperties())
{
var propValue = props.GetValue(po);
if (propValue is IPartial p && p.IsPresent)
propList.Add(new LogEventProperty(props.Name, factory.CreatePropertyValue(p.RawValue, true)));
else if (!(propValue is IPartial))
propList.Add(new LogEventProperty(props.Name, factory.CreatePropertyValue(propValue, true)));
}
result = new StructureValue(propList);
return true;
var propValue = props.GetValue(po);
if (propValue is IPartial p && p.IsPresent)
propList.Add(new LogEventProperty(props.Name, factory.CreatePropertyValue(p.RawValue, true)));
else if (!(propValue is IPartial))
propList.Add(new LogEventProperty(props.Name, factory.CreatePropertyValue(propValue, true)));
}
result = new StructureValue(propList);
return true;
}
}

View File

@@ -1,54 +1,50 @@
using System;
using System.IO;
using Serilog.Formatting.Elasticsearch;
using Serilog.Formatting.Json;
namespace PluralKit.Core
namespace PluralKit.Core;
public class ScalarFormatting
{
public class ScalarFormatting
private static bool Write(object value, TextWriter output)
{
private static bool Write(object value, TextWriter output)
if (value is SystemId si)
output.Write(si.Value);
else if (value is MemberId mi)
output.Write(mi.Value);
else if (value is GroupId gi)
output.Write(gi.Value);
else if (value is SwitchId swi)
output.Write(swi.Value);
else
return false;
return true;
}
private static void WriteV(object value, TextWriter output) => Write(value, output);
public class Elasticsearch: ElasticsearchJsonFormatter
{
public Elasticsearch(bool omitEnclosingObject = false, string closingDelimiter = null,
bool renderMessage = true, IFormatProvider formatProvider = null,
ISerializer serializer = null, bool inlineFields = false,
bool renderMessageTemplate = true, bool formatStackTraceAsArray = false) : base(
omitEnclosingObject, closingDelimiter, renderMessage, formatProvider, serializer, inlineFields,
renderMessageTemplate, formatStackTraceAsArray)
{
if (value is SystemId si)
output.Write(si.Value);
else if (value is MemberId mi)
output.Write(mi.Value);
else if (value is GroupId gi)
output.Write(gi.Value);
else if (value is SwitchId swi)
output.Write(swi.Value);
else
return false;
return true;
AddLiteralWriter(typeof(SystemId), WriteV);
AddLiteralWriter(typeof(MemberId), WriteV);
AddLiteralWriter(typeof(GroupId), WriteV);
AddLiteralWriter(typeof(SwitchId), WriteV);
}
}
private static void WriteV(object value, TextWriter output) => Write(value, output);
public class Elasticsearch: ElasticsearchJsonFormatter
public class JsonValue: JsonValueFormatter
{
protected override void FormatLiteralValue(object value, TextWriter output)
{
public Elasticsearch(bool omitEnclosingObject = false, string closingDelimiter = null,
bool renderMessage = true, IFormatProvider formatProvider = null,
ISerializer serializer = null, bool inlineFields = false,
bool renderMessageTemplate = true, bool formatStackTraceAsArray = false) : base(
omitEnclosingObject, closingDelimiter, renderMessage, formatProvider, serializer, inlineFields,
renderMessageTemplate, formatStackTraceAsArray)
{
AddLiteralWriter(typeof(SystemId), WriteV);
AddLiteralWriter(typeof(MemberId), WriteV);
AddLiteralWriter(typeof(GroupId), WriteV);
AddLiteralWriter(typeof(SwitchId), WriteV);
}
}
public class JsonValue: JsonValueFormatter
{
protected override void FormatLiteralValue(object value, TextWriter output)
{
if (Write(value, output))
return;
base.FormatLiteralValue(value, output);
}
if (Write(value, output))
return;
base.FormatLiteralValue(value, output);
}
}
}