Applied codestyle to all .cs files

This commit is contained in:
Kwoth
2021-12-29 06:07:16 +01:00
parent 723447c7d4
commit 82000c97a4
543 changed files with 13221 additions and 14059 deletions

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
namespace NadekoBot.Common.Yml;
public class CommentAttribute : Attribute
@@ -7,4 +7,4 @@ public class CommentAttribute : Attribute
public CommentAttribute(string comment)
=> Comment = comment;
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using YamlDotNet.Core;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.TypeInspectors;
@@ -17,15 +17,7 @@ public class CommentGatheringTypeInspector : TypeInspectorSkeleton
private sealed class CommentsPropertyDescriptor : IPropertyDescriptor
{
private readonly IPropertyDescriptor baseDescriptor;
public CommentsPropertyDescriptor(IPropertyDescriptor baseDescriptor)
{
this.baseDescriptor = baseDescriptor;
Name = baseDescriptor.Name;
}
public string Name { get; set; }
public string Name { get; }
public Type Type
=> baseDescriptor.Type;
@@ -47,6 +39,14 @@ public class CommentGatheringTypeInspector : TypeInspectorSkeleton
public bool CanWrite
=> baseDescriptor.CanWrite;
private readonly IPropertyDescriptor baseDescriptor;
public CommentsPropertyDescriptor(IPropertyDescriptor baseDescriptor)
{
this.baseDescriptor = baseDescriptor;
Name = baseDescriptor.Name;
}
public void Write(object target, object value)
=> baseDescriptor.Write(target, value);
@@ -62,4 +62,4 @@ public class CommentGatheringTypeInspector : TypeInspectorSkeleton
: baseDescriptor.Read(target);
}
}
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using YamlDotNet.Core;
using YamlDotNet.Serialization;
@@ -6,15 +6,7 @@ namespace NadekoBot.Common.Yml;
public sealed class CommentsObjectDescriptor : IObjectDescriptor
{
private readonly IObjectDescriptor innerDescriptor;
public CommentsObjectDescriptor(IObjectDescriptor innerDescriptor, string comment)
{
this.innerDescriptor = innerDescriptor;
this.Comment = comment;
}
public string Comment { get; private set; }
public string Comment { get; }
public object Value
=> innerDescriptor.Value;
@@ -27,4 +19,12 @@ public sealed class CommentsObjectDescriptor : IObjectDescriptor
public ScalarStyle ScalarStyle
=> innerDescriptor.ScalarStyle;
}
private readonly IObjectDescriptor innerDescriptor;
public CommentsObjectDescriptor(IObjectDescriptor innerDescriptor, string comment)
{
this.innerDescriptor = innerDescriptor;
Comment = comment;
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
@@ -15,12 +15,10 @@ public class CommentsObjectGraphVisitor : ChainedObjectGraphVisitor
public override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, IEmitter context)
{
if (value is CommentsObjectDescriptor commentsDescriptor &&
!string.IsNullOrWhiteSpace(commentsDescriptor.Comment))
{
if (value is CommentsObjectDescriptor commentsDescriptor
&& !string.IsNullOrWhiteSpace(commentsDescriptor.Comment))
context.Emit(new Comment(commentsDescriptor.Comment.Replace("\n", "\n# "), false));
}
return base.EnterMapping(key, value, context);
}
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using YamlDotNet.Core;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.EventEmitters;
@@ -19,12 +19,12 @@ public class MultilineScalarFlowStyleEmitter : ChainedEventEmitter
var value = eventInfo.Source.Value as string;
if (!string.IsNullOrEmpty(value))
{
var isMultiLine = value.IndexOfAny(new char[] { '\r', '\n', '\x85', '\x2028', '\x2029' }) >= 0;
var isMultiLine = value.IndexOfAny(new[] { '\r', '\n', '\x85', '\x2028', '\x2029' }) >= 0;
if (isMultiLine)
eventInfo = new(eventInfo.Source) { Style = ScalarStyle.Literal, };
eventInfo = new(eventInfo.Source) { Style = ScalarStyle.Literal };
}
}
nextEmitter.Emit(eventInfo, emitter);
}
}
}

View File

@@ -1,6 +1,6 @@
#nullable disable
using System.Globalization;
#nullable disable
using SixLabors.ImageSharp.PixelFormats;
using System.Globalization;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
@@ -44,4 +44,4 @@ public class CultureInfoConverter : IYamlTypeConverter
var ci = (CultureInfo)value;
emitter.Emit(new Scalar(ci.Name));
}
}
}

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
@@ -22,4 +22,4 @@ public class UriConverter : IYamlTypeConverter
var uri = (Uri)value;
emitter.Emit(new Scalar(uri.ToString()));
}
}
}

View File

@@ -1,5 +1,6 @@
#nullable disable
#nullable disable
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace NadekoBot.Common.Yml;
@@ -7,21 +8,21 @@ public class Yaml
{
public static ISerializer Serializer
=> new SerializerBuilder().WithTypeInspector(inner => new CommentGatheringTypeInspector(inner))
.WithEmissionPhaseObjectGraphVisitor(args => new CommentsObjectGraphVisitor(args.InnerVisitor))
.WithEventEmitter(args => new MultilineScalarFlowStyleEmitter(args))
.WithNamingConvention(YamlDotNet.Serialization.NamingConventions.CamelCaseNamingConvention.Instance)
.WithIndentedSequences()
.WithTypeConverter(new Rgba32Converter())
.WithTypeConverter(new CultureInfoConverter())
.WithTypeConverter(new UriConverter())
.Build();
.WithEmissionPhaseObjectGraphVisitor(args
=> new CommentsObjectGraphVisitor(args.InnerVisitor))
.WithEventEmitter(args => new MultilineScalarFlowStyleEmitter(args))
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithIndentedSequences()
.WithTypeConverter(new Rgba32Converter())
.WithTypeConverter(new CultureInfoConverter())
.WithTypeConverter(new UriConverter())
.Build();
public static IDeserializer Deserializer
=> new DeserializerBuilder()
.WithNamingConvention(YamlDotNet.Serialization.NamingConventions.CamelCaseNamingConvention.Instance)
.WithTypeConverter(new Rgba32Converter())
.WithTypeConverter(new CultureInfoConverter())
.WithTypeConverter(new UriConverter())
.IgnoreUnmatchedProperties()
.Build();
}
=> new DeserializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithTypeConverter(new Rgba32Converter())
.WithTypeConverter(new CultureInfoConverter())
.WithTypeConverter(new UriConverter())
.IgnoreUnmatchedProperties()
.Build();
}

View File

@@ -1,12 +1,12 @@
#nullable disable
#nullable disable
namespace NadekoBot.Common.Yml;
public class YamlHelper
{
// https://github.com/aaubry/YamlDotNet/blob/0f4cc205e8b2dd8ef6589d96de32bf608a687c6f/YamlDotNet/Core/Scanner.cs#L1687
/// <summary>
/// This is modified code from yamldotnet's repo which handles parsing unicode code points
/// it is needed as yamldotnet doesn't support unescaped unicode characters
/// This is modified code from yamldotnet's repo which handles parsing unicode code points
/// it is needed as yamldotnet doesn't support unescaped unicode characters
/// </summary>
/// <param name="point">Unicode code point</param>
/// <returns>Actual character</returns>
@@ -18,20 +18,14 @@ public class YamlHelper
foreach (var c in point)
{
if (!IsHex(c))
{
return point;
}
if (!IsHex(c)) return point;
character = (character << 4) + AsHex(c);
}
// Check the value and write the character.
if (character is (>= 0xD800 and <= 0xDFFF) or > 0x10FFFF)
{
return point;
}
if (character is (>= 0xD800 and <= 0xDFFF) or > 0x10FFFF) return point;
return char.ConvertFromUtf32(character);
}
@@ -41,16 +35,10 @@ public class YamlHelper
public static int AsHex(char c)
{
if (c <= '9')
{
return c - '0';
}
if (c <= '9') return c - '0';
if (c <= 'F')
{
return c - 'A' + 10;
}
if (c <= 'F') return c - 'A' + 10;
return c - 'a' + 10;
}
}
}