From a19a04be8e99f30d2b612ff244b2002203957964 Mon Sep 17 00:00:00 2001 From: Jiu Date: Sun, 31 Mar 2024 16:47:08 +0200 Subject: [PATCH] refactor: reformat and cleanup --- .../Rin.Core.Reflection.csproj | 2 +- .../TypeDescriptors/DictionaryDescriptor.cs | 4 +- .../TypeDescriptors/ObjectDescriptor.cs | 2 +- Rin.Core.Yaml/Parser.cs | 2 +- Rin.Core.Yaml/Properties/AssemblyInfo.cs | 49 ------------------- Rin.Core.Yaml/Rin.Core.Yaml.csproj | 4 +- Rin.Core.Yaml/Scanner.cs | 5 +- Rin.Core.Yaml/Serialization/Serializer.cs | 7 ++- .../Serializers/PrimitiveSerializer.cs | 2 +- .../Serialization/YamlAssemblyRegistry.cs | 2 +- .../Serialization/YamlSequenceNode.cs | 4 +- Rin.Core.Yaml/TagDirectiveCollection.cs | 1 - 12 files changed, 19 insertions(+), 65 deletions(-) delete mode 100644 Rin.Core.Yaml/Properties/AssemblyInfo.cs diff --git a/Rin.Core.Reflection.Yaml/Rin.Core.Reflection.csproj b/Rin.Core.Reflection.Yaml/Rin.Core.Reflection.csproj index d132b5e..e97cd74 100644 --- a/Rin.Core.Reflection.Yaml/Rin.Core.Reflection.csproj +++ b/Rin.Core.Reflection.Yaml/Rin.Core.Reflection.csproj @@ -5,6 +5,6 @@ enable - + diff --git a/Rin.Core.Reflection.Yaml/TypeDescriptors/DictionaryDescriptor.cs b/Rin.Core.Reflection.Yaml/TypeDescriptors/DictionaryDescriptor.cs index ff9dc9e..743a3d2 100644 --- a/Rin.Core.Reflection.Yaml/TypeDescriptors/DictionaryDescriptor.cs +++ b/Rin.Core.Reflection.Yaml/TypeDescriptors/DictionaryDescriptor.cs @@ -147,9 +147,7 @@ public void SetValue(object dictionary, object key, object value) { } else { // Only throw an exception if the addMethod is not accessible when adding to a dictionary if (indexerSetter == null) { - throw new InvalidOperationException( - $"No indexer this[key] method found on dictionary [{Type}]" - ); + throw new InvalidOperationException($"No indexer this[key] method found on dictionary [{Type}]"); } indexerSetter.Invoke(dictionary, [key, value]); diff --git a/Rin.Core.Reflection.Yaml/TypeDescriptors/ObjectDescriptor.cs b/Rin.Core.Reflection.Yaml/TypeDescriptors/ObjectDescriptor.cs index 09fc91b..b550b24 100644 --- a/Rin.Core.Reflection.Yaml/TypeDescriptors/ObjectDescriptor.cs +++ b/Rin.Core.Reflection.Yaml/TypeDescriptors/ObjectDescriptor.cs @@ -185,7 +185,7 @@ protected virtual List PrepareMembers() { var bindingFlags = BindingFlags.Instance | BindingFlags.Public; - var metadataTypeAttributes = Type.GetCustomAttributes(inherit: true); + var metadataTypeAttributes = Type.GetCustomAttributes(true); var metadataClassMemberInfos = metadataTypeAttributes.Any() ? new List<(MemberInfo MemberInfo, Type MemberType)>() : null; foreach (var metadataTypeAttr in metadataTypeAttributes) { diff --git a/Rin.Core.Yaml/Parser.cs b/Rin.Core.Yaml/Parser.cs index 873c964..93291a2 100644 --- a/Rin.Core.Yaml/Parser.cs +++ b/Rin.Core.Yaml/Parser.cs @@ -193,7 +193,7 @@ Event ParseDocumentStart(bool isImplicit) { states.Push(ParserState.YamlParseDocumentEndState); state = ParserState.YamlParseBlockNodeState; - + return new Events.DocumentStart(null, directives, true, GetCurrentToken().Start, GetCurrentToken().End); } diff --git a/Rin.Core.Yaml/Properties/AssemblyInfo.cs b/Rin.Core.Yaml/Properties/AssemblyInfo.cs deleted file mode 100644 index 8bd6c27..0000000 --- a/Rin.Core.Yaml/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2015 SharpYaml - Alexandre Mutel -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -// ------------------------------------------------------------------------------- -// SharpYaml is a fork of YamlDotNet https://github.com/aaubry/YamlDotNet -// published with the following license: -// ------------------------------------------------------------------------------- -// -// Copyright (c) 2008, 2009, 2010, 2011, 2012 Antoine Aubry -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -// of the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Reflection; -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("Stride.Core.Yaml.Tests")] diff --git a/Rin.Core.Yaml/Rin.Core.Yaml.csproj b/Rin.Core.Yaml/Rin.Core.Yaml.csproj index a394c35..b1ec56c 100644 --- a/Rin.Core.Yaml/Rin.Core.Yaml.csproj +++ b/Rin.Core.Yaml/Rin.Core.Yaml.csproj @@ -5,7 +5,7 @@ enable - - + + diff --git a/Rin.Core.Yaml/Scanner.cs b/Rin.Core.Yaml/Scanner.cs index 6aa043a..8242da4 100644 --- a/Rin.Core.Yaml/Scanner.cs +++ b/Rin.Core.Yaml/Scanner.cs @@ -1006,7 +1006,7 @@ Token ScanBlockScalar(bool isLiteral) { } var end = mark; - + // Set the indentation level if it was specified. if (increment != 0) { currentIndent = indent >= 0 ? indent + increment : increment; @@ -1219,6 +1219,7 @@ Token ScanFlowScalar(bool isSingleQuoted) { "While parsing a quoted scalar, find unknown escape character." ); } + break; } @@ -1463,7 +1464,7 @@ Token ScanPlainScalar() { /// void RemoveSimpleKey() { var key = simpleKeys.Peek(); - + if (key is { IsPossible: true, IsRequired: true }) { // If the key is required, it is an error. throw new SyntaxErrorException( diff --git a/Rin.Core.Yaml/Serialization/Serializer.cs b/Rin.Core.Yaml/Serialization/Serializer.cs index 1d7a569..8f0a621 100644 --- a/Rin.Core.Yaml/Serialization/Serializer.cs +++ b/Rin.Core.Yaml/Serialization/Serializer.cs @@ -139,7 +139,12 @@ public void Serialize(IEmitter emitter, object graph) { /// The object to serialize. /// The static type of the object to serialize. /// The context settings. - public void Serialize(IEmitter emitter, object graph, Type type, SerializerContextSettings? contextSettings = null) { + public void Serialize( + IEmitter emitter, + object graph, + Type type, + SerializerContextSettings? contextSettings = null + ) { if (emitter == null) { throw new ArgumentNullException(nameof(emitter)); } diff --git a/Rin.Core.Yaml/Serialization/Serializers/PrimitiveSerializer.cs b/Rin.Core.Yaml/Serialization/Serializers/PrimitiveSerializer.cs index cc4d919..2caeb5a 100644 --- a/Rin.Core.Yaml/Serialization/Serializers/PrimitiveSerializer.cs +++ b/Rin.Core.Yaml/Serialization/Serializers/PrimitiveSerializer.cs @@ -29,7 +29,7 @@ public override object ConvertFrom(ref ObjectContext context, Scalar scalar) { // If type is an enum, try to parse it if (type.IsEnum) { - var result = primitiveType.ParseEnum(text, out bool enumRemapped); + var result = primitiveType.ParseEnum(text, out var enumRemapped); if (enumRemapped) { context.SerializerContext.HasRemapOccurred = true; } diff --git a/Rin.Core.Yaml/Serialization/YamlAssemblyRegistry.cs b/Rin.Core.Yaml/Serialization/YamlAssemblyRegistry.cs index 27fd8a2..57c7ffa 100644 --- a/Rin.Core.Yaml/Serialization/YamlAssemblyRegistry.cs +++ b/Rin.Core.Yaml/Serialization/YamlAssemblyRegistry.cs @@ -76,7 +76,7 @@ public void RegisterAssembly(Assembly assembly, IAttributeRegistry attributeRegi var assemblyScanTypes = AssemblyRegistry.GetScanTypes(assembly); if (assemblyScanTypes != null) { // Register serializer factories - if (assemblyScanTypes.Types.TryGetValue(typeof(IYamlSerializableFactory), out List types)) { + if (assemblyScanTypes.Types.TryGetValue(typeof(IYamlSerializableFactory), out var types)) { foreach (var type in types) { if (typeof(IYamlSerializableFactory).IsAssignableFrom(type) && type.GetConstructor(Type.EmptyTypes) != null) { diff --git a/Rin.Core.Yaml/Serialization/YamlSequenceNode.cs b/Rin.Core.Yaml/Serialization/YamlSequenceNode.cs index 47c3d28..ff28c15 100644 --- a/Rin.Core.Yaml/Serialization/YamlSequenceNode.cs +++ b/Rin.Core.Yaml/Serialization/YamlSequenceNode.cs @@ -28,7 +28,7 @@ public class YamlSequenceNode : YamlNode, IEnumerable { public override IEnumerable AllNodes { get { yield return this; - + foreach (var child in Children) { foreach (var node in child.AllNodes) { yield return node; @@ -87,7 +87,7 @@ public YamlSequenceNode(params YamlNode[] children) /// public YamlSequenceNode(IEnumerable children) { foreach (var child in children) { - this.Children.Add(child); + Children.Add(child); } } diff --git a/Rin.Core.Yaml/TagDirectiveCollection.cs b/Rin.Core.Yaml/TagDirectiveCollection.cs index 2db83f6..b3efed8 100644 --- a/Rin.Core.Yaml/TagDirectiveCollection.cs +++ b/Rin.Core.Yaml/TagDirectiveCollection.cs @@ -1,5 +1,4 @@ using Rin.Core.Yaml.Tokens; -using System.Collections.Generic; using System.Collections.ObjectModel; namespace Rin.Core.Yaml;