diff --git a/YamlDotNet.Benchmark/YamlDotNet.Benchmark.csproj b/YamlDotNet.Benchmark/YamlDotNet.Benchmark.csproj index a9e0b4a97..f3c848871 100644 --- a/YamlDotNet.Benchmark/YamlDotNet.Benchmark.csproj +++ b/YamlDotNet.Benchmark/YamlDotNet.Benchmark.csproj @@ -5,7 +5,6 @@ net8.0;net47 enable enable - 10.0 diff --git a/YamlDotNet/Core/AnchorName.cs b/YamlDotNet/Core/AnchorName.cs index d51817778..da88394bc 100644 --- a/YamlDotNet/Core/AnchorName.cs +++ b/YamlDotNet/Core/AnchorName.cs @@ -24,7 +24,7 @@ namespace YamlDotNet.Core { - public struct AnchorName : IEquatable + public readonly struct AnchorName : IEquatable { public static readonly AnchorName Empty; diff --git a/YamlDotNet/Core/Emitter.cs b/YamlDotNet/Core/Emitter.cs index dc786e05e..333043c71 100644 --- a/YamlDotNet/Core/Emitter.cs +++ b/YamlDotNet/Core/Emitter.cs @@ -41,7 +41,7 @@ public class Emitter : IEmitter private static readonly Regex UriReplacer = new Regex(@"[^0-9A-Za-z_\-;?@=$~\\\)\]/:&+,\.\*\(\[!]", StandardRegexOptions.Compiled | RegexOptions.Singleline); - private static readonly string[] newLineSeparators = new[] { "\r\n", "\r", "\n" }; + private static readonly string[] NewLineSeparators = ["\r\n", "\r", "\n"]; private readonly TextWriter output; private readonly bool outputUsesUnicodeEncoding; @@ -653,7 +653,7 @@ private void EmitComment(Comment comment) return; } - var lines = comment.Value.Split(newLineSeparators, StringSplitOptions.None); + var lines = comment.Value.Split(NewLineSeparators, StringSplitOptions.None); if (comment.IsInline) { diff --git a/YamlDotNet/Core/InsertionQueue.cs b/YamlDotNet/Core/InsertionQueue.cs index 0f812ab1a..8071d1d2b 100644 --- a/YamlDotNet/Core/InsertionQueue.cs +++ b/YamlDotNet/Core/InsertionQueue.cs @@ -39,7 +39,9 @@ public sealed class InsertionQueue : IEnumerable private int readPtr; private int writePtr; private int mask; +#pragma warning disable IDE0032 private int count; +#pragma warning restore IDE0032 public InsertionQueue(int initialCapacity = DefaultInitialCapacity) { diff --git a/YamlDotNet/Core/MergingParser.cs b/YamlDotNet/Core/MergingParser.cs index 8d635e7a8..7a435da7c 100644 --- a/YamlDotNet/Core/MergingParser.cs +++ b/YamlDotNet/Core/MergingParser.cs @@ -162,7 +162,7 @@ private IEnumerable GetMappingEvents(AnchorName anchor) return events.FromAnchor(anchor).Where(e => !this.events.IsDeleted(e)) .Select(e => e.Value) .TakeWhile(e => (nesting += e.NestingIncrease) >= 0) - .Select(e => cloner.Clone(e)); + .Select(cloner.Clone); } private sealed class ParsingEventCollection : IEnumerable> diff --git a/YamlDotNet/Core/ParserExtensions.cs b/YamlDotNet/Core/ParserExtensions.cs index b94e875ab..188005197 100644 --- a/YamlDotNet/Core/ParserExtensions.cs +++ b/YamlDotNet/Core/ParserExtensions.cs @@ -170,7 +170,7 @@ public static bool Accept(this IParser parser) where T : ParsingEvent /// otherwise returns false. public static bool TryFindMappingEntry(this IParser parser, Func selector, [MaybeNullWhen(false)] out Scalar? key, [MaybeNullWhen(false)] out ParsingEvent? value) { - if (parser.TryConsume(out var _start)) + if (parser.TryConsume(out _)) { while (parser.Current != null) { diff --git a/YamlDotNet/Core/Scanner.cs b/YamlDotNet/Core/Scanner.cs index 90b7b48cc..291997b88 100644 --- a/YamlDotNet/Core/Scanner.cs +++ b/YamlDotNet/Core/Scanner.cs @@ -67,7 +67,6 @@ public class Scanner : IScanner private bool streamStartProduced; private bool streamEndProduced; private bool plainScalarFollowedByComment; - private long flowSequenceStartLine; private bool flowCollectionFetched; private bool startFlowCollectionFetched; private long indent = -1; @@ -933,7 +932,6 @@ private void FetchFlowCollectionStart(bool isSequenceToken) if (isSequenceToken) { token = new FlowSequenceStart(start, start); - flowSequenceStartLine = token.Start.Line; } else { @@ -2520,7 +2518,7 @@ private string ScanTagUri(string? head, Mark start) return result; } - private static readonly byte[] EmptyBytes = Array.Empty(); + private static readonly byte[] EmptyBytes = []; /// /// Decode an URI-escape sequence corresponding to a single UTF-8 character. diff --git a/YamlDotNet/GlobalSuppressions.cs b/YamlDotNet/GlobalSuppressions.cs deleted file mode 100644 index 2ecfc559f..000000000 --- a/YamlDotNet/GlobalSuppressions.cs +++ /dev/null @@ -1,27 +0,0 @@ -// This file is part of YamlDotNet - A .NET library for YAML. -// Copyright (c) Antoine Aubry and contributors -// -// 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. - -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. - -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0056:Use index operator", Justification = "Not available on older platforms", Scope = "member", Target = "~M:YamlDotNet.Core.Scanner.ScanTag~YamlDotNet.Core.Tokens.Token")] diff --git a/YamlDotNet/Helpers/ExpressionExtensions.cs b/YamlDotNet/Helpers/ExpressionExtensions.cs index 73596f19a..fb207a6da 100644 --- a/YamlDotNet/Helpers/ExpressionExtensions.cs +++ b/YamlDotNet/Helpers/ExpressionExtensions.cs @@ -19,8 +19,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#if !NET20 - using System; using System.Diagnostics.CodeAnalysis; using System.Linq.Expressions; @@ -82,4 +80,3 @@ private static TMemberInfo TryGetMemberExpression(LambdaExpression } } } -#endif diff --git a/YamlDotNet/Helpers/Polyfills.cs b/YamlDotNet/Helpers/Polyfills.cs index 264049c5a..d7c5192a8 100644 --- a/YamlDotNet/Helpers/Polyfills.cs +++ b/YamlDotNet/Helpers/Polyfills.cs @@ -19,7 +19,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#pragma warning disable IDE0130 namespace YamlDotNet +#pragma warning restore IDE0130 { internal static class Polyfills { diff --git a/YamlDotNet/ReflectionExtensions.cs b/YamlDotNet/ReflectionExtensions.cs index 4b403d302..9cac5d066 100644 --- a/YamlDotNet/ReflectionExtensions.cs +++ b/YamlDotNet/ReflectionExtensions.cs @@ -305,12 +305,13 @@ public static Attribute[] GetAllCustomAttributes(this PropertyInfo m return Attribute.GetCustomAttributes(member, typeof(TAttribute), inherit: true); } - private static readonly ConcurrentDictionary typesHaveNullContext = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary TypesHaveNullContext = new(); + public static bool AcceptsNull(this MemberInfo member) { var result = true; //default to allowing nulls, this will be set to false if there is a null context on the type #if NET8_0_OR_GREATER - var typeHasNullContext = typesHaveNullContext.GetOrAdd(member.DeclaringType, (Type t) => + var typeHasNullContext = TypesHaveNullContext.GetOrAdd(member.DeclaringType, (Type t) => { var attributes = t.GetCustomAttributes(typeof(System.Runtime.CompilerServices.NullableContextAttribute), true); return (attributes?.Length ?? 0) > 0; @@ -325,7 +326,7 @@ public static bool AcceptsNull(this MemberInfo member) return result; #else - var typeHasNullContext = typesHaveNullContext.GetOrAdd(member.DeclaringType, (Type t) => + var typeHasNullContext = TypesHaveNullContext.GetOrAdd(member.DeclaringType, (Type t) => { var attributes = t.GetCustomAttributes(true); return attributes.Any(x => x.GetType().FullName == "System.Runtime.CompilerServices.NullableContextAttribute"); diff --git a/YamlDotNet/RepresentationModel/YamlMappingNode.cs b/YamlDotNet/RepresentationModel/YamlMappingNode.cs index 823678095..85c22a735 100644 --- a/YamlDotNet/RepresentationModel/YamlMappingNode.cs +++ b/YamlDotNet/RepresentationModel/YamlMappingNode.cs @@ -196,19 +196,13 @@ internal override void ResolveAliases(DocumentLoadingState state) { if (entry.Key is YamlAliasNode) { - if (keysToUpdate == null) - { - keysToUpdate = new Dictionary(); - } + keysToUpdate ??= new Dictionary(); // TODO: The representation model should be redesigned, because here the anchor could be null but that would be invalid YAML keysToUpdate.Add(entry.Key, state.GetNode(entry.Key.Anchor!, entry.Key.Start, entry.Key.End)); } if (entry.Value is YamlAliasNode) { - if (valuesToUpdate == null) - { - valuesToUpdate = new Dictionary(); - } + valuesToUpdate ??= new Dictionary(); // TODO: The representation model should be redesigned, because here the anchor could be null but that would be invalid YAML valuesToUpdate.Add(entry.Key, state.GetNode(entry.Value.Anchor!, entry.Value.Start, entry.Value.End)); } diff --git a/YamlDotNet/RepresentationModel/YamlScalarNode.cs b/YamlDotNet/RepresentationModel/YamlScalarNode.cs index 2697496a1..42748d56c 100644 --- a/YamlDotNet/RepresentationModel/YamlScalarNode.cs +++ b/YamlDotNet/RepresentationModel/YamlScalarNode.cs @@ -37,8 +37,8 @@ namespace YamlDotNet.RepresentationModel [DebuggerDisplay("{Value}")] public sealed class YamlScalarNode : YamlNode, IYamlConvertible { - private bool _forceImplicitPlain; - private string? _value; + private bool forceImplicitPlain; + private string? value; /// /// Gets or sets the value of the node. @@ -46,19 +46,19 @@ public sealed class YamlScalarNode : YamlNode, IYamlConvertible /// The value. public string? Value { - get => _value; + get => value; set { if (value == null) { - _forceImplicitPlain = true; + forceImplicitPlain = true; } else { - _forceImplicitPlain = false; + forceImplicitPlain = false; } - _value = value; + this.value = value; } } @@ -86,7 +86,7 @@ private void Load(IParser parser, DocumentLoadingState state) var value = scalar.Value; if (scalar.Style == ScalarStyle.Plain && Tag.IsEmpty) { - _forceImplicitPlain = value.Length switch + forceImplicitPlain = value.Length switch { // we have an implicit null value without a tag stating it, fake it out 0 => true, @@ -97,7 +97,7 @@ private void Load(IParser parser, DocumentLoadingState state) }; } - _value = value; + this.value = value; Style = scalar.Style; } @@ -136,7 +136,7 @@ internal override void Emit(IEmitter emitter, EmitterState state) var tag = Tag; var implicitPlain = tag.IsEmpty; - if (_forceImplicitPlain && + if (forceImplicitPlain && Style == ScalarStyle.Plain && (Value == null || Value == "")) { diff --git a/YamlDotNet/RepresentationModel/YamlStream.cs b/YamlDotNet/RepresentationModel/YamlStream.cs index 9a744243e..326f4526b 100644 --- a/YamlDotNet/RepresentationModel/YamlStream.cs +++ b/YamlDotNet/RepresentationModel/YamlStream.cs @@ -31,7 +31,7 @@ namespace YamlDotNet.RepresentationModel /// public class YamlStream : IEnumerable { - private readonly IList documents = new List(); + private readonly List documents = []; /// /// Gets the documents inside the stream. diff --git a/YamlDotNet/Serialization/Converters/DateTime8601Converter.cs b/YamlDotNet/Serialization/Converters/DateTime8601Converter.cs index 8dd7084f0..6d42f5016 100644 --- a/YamlDotNet/Serialization/Converters/DateTime8601Converter.cs +++ b/YamlDotNet/Serialization/Converters/DateTime8601Converter.cs @@ -31,7 +31,6 @@ namespace YamlDotNet.Serialization.Converters /// public class DateTime8601Converter : IYamlTypeConverter { - private readonly IFormatProvider provider; private readonly ScalarStyle scalarStyle; /// @@ -47,7 +46,6 @@ public DateTime8601Converter() /// public DateTime8601Converter(ScalarStyle scalarStyle) { - this.provider = CultureInfo.InvariantCulture; this.scalarStyle = scalarStyle; } diff --git a/YamlDotNet/Serialization/Deserializer.cs b/YamlDotNet/Serialization/Deserializer.cs index c514fa1bf..7555934bb 100644 --- a/YamlDotNet/Serialization/Deserializer.cs +++ b/YamlDotNet/Serialization/Deserializer.cs @@ -84,17 +84,17 @@ public T Deserialize(IParser parser) public object? Deserialize(string input) { - return Deserialize(input, typeof(object)); + return Deserialize(input); } public object? Deserialize(TextReader input) { - return Deserialize(input, typeof(object)); + return Deserialize(input); } public object? Deserialize(IParser parser) { - return Deserialize(parser, typeof(object)); + return Deserialize(parser); } public object? Deserialize(string input, Type type) diff --git a/YamlDotNet/Serialization/EventEmitters/JsonEventEmitter.cs b/YamlDotNet/Serialization/EventEmitters/JsonEventEmitter.cs index d1f413c85..497866735 100644 --- a/YamlDotNet/Serialization/EventEmitters/JsonEventEmitter.cs +++ b/YamlDotNet/Serialization/EventEmitters/JsonEventEmitter.cs @@ -32,7 +32,7 @@ public sealed class JsonEventEmitter : ChainedEventEmitter private readonly YamlFormatter formatter; private readonly INamingConvention enumNamingConvention; private readonly ITypeInspector typeInspector; - private static readonly Regex numericRegex = new Regex(@"^-?\d+\.?\d+$", RegexOptions.Compiled); + private static readonly Regex NumericRegex = new Regex(@"^-?\d+\.?\d+$", RegexOptions.Compiled); public JsonEventEmitter(IEventEmitter nextEmitter, YamlFormatter formatter, INamingConvention enumNamingConvention, ITypeInspector typeInspector) : base(nextEmitter) @@ -90,7 +90,7 @@ public override void Emit(ScalarEventInfo eventInfo, IEmitter emitter) case TypeCode.Decimal: eventInfo.RenderedValue = formatter.FormatNumber(value); - if (!numericRegex.IsMatch(eventInfo.RenderedValue)) + if (!NumericRegex.IsMatch(eventInfo.RenderedValue)) { eventInfo.Style = ScalarStyle.DoubleQuoted; } diff --git a/YamlDotNet/Serialization/NodeDeserializers/DictionaryNodeDeserializer.cs b/YamlDotNet/Serialization/NodeDeserializers/DictionaryNodeDeserializer.cs index f20e19134..0efe35ea0 100644 --- a/YamlDotNet/Serialization/NodeDeserializers/DictionaryNodeDeserializer.cs +++ b/YamlDotNet/Serialization/NodeDeserializers/DictionaryNodeDeserializer.cs @@ -23,9 +23,7 @@ using System.Collections; using System.Collections.Generic; using YamlDotNet.Core; -using YamlDotNet.Core.Events; using YamlDotNet.Helpers; -using YamlDotNet.Serialization.Utilities; namespace YamlDotNet.Serialization.NodeDeserializers { @@ -53,11 +51,9 @@ public bool Deserialize(IParser parser, Type expectedType, Func but not IDictionary - dictionary = (IDictionary?)Activator.CreateInstance(typeof(GenericDictionaryToNonGenericAdapter<,>).MakeGenericType(keyType, valueType), value); - } + + // Uncommon case where a type implements IDictionary but not IDictionary + dictionary ??= (IDictionary?)Activator.CreateInstance(typeof(GenericDictionaryToNonGenericAdapter<,>).MakeGenericType(keyType, valueType), value); } else if (typeof(IDictionary).IsAssignableFrom(expectedType)) { diff --git a/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs b/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs index f7dfbe965..95ff8f5ff 100644 --- a/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs +++ b/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs @@ -142,7 +142,7 @@ public bool Deserialize(IParser parser, Type expectedType, Func nestedObjectDeserializer, out object? value, ObjectDeserializer rootDeserializer) { - if (_objectFactory.IsDictionary(expectedType)) + if (objectFactory.IsDictionary(expectedType)) { - var result = _objectFactory.Create(expectedType) as IDictionary; + var result = objectFactory.Create(expectedType) as IDictionary; if (result == null) { value = null; return false; } - var keyType = _objectFactory.GetKeyType(expectedType); - var valueType = _objectFactory.GetValueType(expectedType); + var keyType = objectFactory.GetKeyType(expectedType); + var valueType = objectFactory.GetValueType(expectedType); value = result; base.Deserialize(keyType, valueType, reader, nestedObjectDeserializer, result, rootDeserializer); diff --git a/YamlDotNet/Serialization/NodeTypeResolvers/MappingNodeTypeResolver.cs b/YamlDotNet/Serialization/NodeTypeResolvers/MappingNodeTypeResolver.cs index 5d974aa7c..bf21c1077 100644 --- a/YamlDotNet/Serialization/NodeTypeResolvers/MappingNodeTypeResolver.cs +++ b/YamlDotNet/Serialization/NodeTypeResolvers/MappingNodeTypeResolver.cs @@ -27,7 +27,7 @@ namespace YamlDotNet.Serialization.NodeTypeResolvers { public class MappingNodeTypeResolver : INodeTypeResolver { - private readonly IDictionary _mappings; + private readonly IDictionary mappings; public MappingNodeTypeResolver(IDictionary mappings) { @@ -44,12 +44,12 @@ public MappingNodeTypeResolver(IDictionary mappings) } } - _mappings = mappings; + this.mappings = mappings; } public bool Resolve(NodeEvent? nodeEvent, ref Type currentType) { - if (_mappings.TryGetValue(currentType, out var concreteType)) + if (mappings.TryGetValue(currentType, out var concreteType)) { currentType = concreteType; return true; diff --git a/YamlDotNet/Serialization/ObjectFactories/DefaultObjectFactory.cs b/YamlDotNet/Serialization/ObjectFactories/DefaultObjectFactory.cs index eb9b28898..b5b0ec6b2 100644 --- a/YamlDotNet/Serialization/ObjectFactories/DefaultObjectFactory.cs +++ b/YamlDotNet/Serialization/ObjectFactories/DefaultObjectFactory.cs @@ -34,7 +34,7 @@ namespace YamlDotNet.Serialization.ObjectFactories /// public sealed class DefaultObjectFactory : ObjectFactoryBase { - private readonly Dictionary> _stateMethods = new Dictionary> + private readonly Dictionary> stateMethods = new() { { typeof(OnDeserializedAttribute), new ConcurrentDictionary() }, { typeof(OnDeserializingAttribute), new ConcurrentDictionary() }, @@ -42,7 +42,7 @@ public sealed class DefaultObjectFactory : ObjectFactoryBase { typeof(OnSerializingAttribute), new ConcurrentDictionary() }, }; - private readonly Dictionary DefaultGenericInterfaceImplementations = new Dictionary + private readonly Dictionary defaultGenericInterfaceImplementations = new() { { typeof(IEnumerable<>), typeof(List<>) }, { typeof(ICollection<>), typeof(List<>) }, @@ -50,7 +50,7 @@ public sealed class DefaultObjectFactory : ObjectFactoryBase { typeof(IDictionary<,>), typeof(Dictionary<,>) } }; - private readonly Dictionary DefaultNonGenericInterfaceImplementations = new Dictionary + private readonly Dictionary defaultNonGenericInterfaceImplementations = new() { { typeof(IEnumerable), typeof(List) }, { typeof(ICollection), typeof(List) }, @@ -79,7 +79,7 @@ public DefaultObjectFactory(IDictionary mappings, Settings settings) throw new InvalidOperationException($"Type '{pair.Value}' does not implement type '{pair.Key}'."); } - DefaultNonGenericInterfaceImplementations.Add(pair.Key, pair.Value); + defaultNonGenericInterfaceImplementations.Add(pair.Key, pair.Value); } this.settings = settings; @@ -91,14 +91,14 @@ public override object Create(Type type) { if (type.IsGenericType()) { - if (DefaultGenericInterfaceImplementations.TryGetValue(type.GetGenericTypeDefinition(), out var implementationType)) + if (defaultGenericInterfaceImplementations.TryGetValue(type.GetGenericTypeDefinition(), out var implementationType)) { type = implementationType.MakeGenericType(type.GetGenericArguments()); } } else { - if (DefaultNonGenericInterfaceImplementations.TryGetValue(type, out var implementationType)) + if (defaultNonGenericInterfaceImplementations.TryGetValue(type, out var implementationType)) { type = implementationType; } @@ -146,7 +146,7 @@ private void ExecuteState(Type attributeType, object value) private MethodInfo[] GetStateMethods(Type attributeType, Type valueType) { - var stateDictionary = _stateMethods[attributeType]; + var stateDictionary = stateMethods[attributeType]; return stateDictionary.GetOrAdd(valueType, type => diff --git a/YamlDotNet/Serialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs b/YamlDotNet/Serialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs index ce188f452..3a26a1199 100644 --- a/YamlDotNet/Serialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs +++ b/YamlDotNet/Serialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs @@ -62,7 +62,7 @@ void IObjectGraphTraversalStrategy.Traverse(IObjectDescriptor graph, I Traverse(null, "", graph, visitor, context, new Stack(maxRecursion), serializer); } - protected struct ObjectPathSegment + protected readonly struct ObjectPathSegment { public readonly object Name; public readonly IObjectDescriptor Value; diff --git a/YamlDotNet/Serialization/ObjectGraphVisitors/PreProcessingPhaseObjectGraphVisitorSkeleton.cs b/YamlDotNet/Serialization/ObjectGraphVisitors/PreProcessingPhaseObjectGraphVisitorSkeleton.cs index b0c9a4cc4..7f666003e 100644 --- a/YamlDotNet/Serialization/ObjectGraphVisitors/PreProcessingPhaseObjectGraphVisitorSkeleton.cs +++ b/YamlDotNet/Serialization/ObjectGraphVisitors/PreProcessingPhaseObjectGraphVisitorSkeleton.cs @@ -36,7 +36,7 @@ public abstract class PreProcessingPhaseObjectGraphVisitorSkeleton : IObjectGrap public PreProcessingPhaseObjectGraphVisitorSkeleton(IEnumerable typeConverters) { - var tcs = typeConverters?.ToArray() ?? Array.Empty(); + var tcs = typeConverters?.ToArray() ?? []; this.typeConverters = tcs; this.typeConverterCache = new TypeConverterCache(tcs); diff --git a/YamlDotNet/Serialization/SerializerBuilder.cs b/YamlDotNet/Serialization/SerializerBuilder.cs index 808ac6663..10cfb9695 100755 --- a/YamlDotNet/Serialization/SerializerBuilder.cs +++ b/YamlDotNet/Serialization/SerializerBuilder.cs @@ -761,7 +761,10 @@ public void SerializeValue(IEmitter emitter, object? value, Type? type) var preProcessingPhaseObjectGraphVisitors = preProcessingPhaseObjectGraphVisitorFactories.BuildComponentList(typeConverters); - void NestedObjectSerializer(object? v, Type? t) => SerializeValue(emitter, v, t); + void NestedObjectSerializer(object? v, Type? t) + { + SerializeValue(emitter, v, t); + } var emittingVisitor = emissionPhaseObjectGraphVisitorFactories.BuildComponentChain( new EmittingObjectGraphVisitor(eventEmitter), diff --git a/YamlDotNet/Serialization/StaticSerializerBuilder.cs b/YamlDotNet/Serialization/StaticSerializerBuilder.cs index 09e5530b3..f561cc9fa 100644 --- a/YamlDotNet/Serialization/StaticSerializerBuilder.cs +++ b/YamlDotNet/Serialization/StaticSerializerBuilder.cs @@ -755,7 +755,10 @@ public void SerializeValue(IEmitter emitter, object? value, Type? type) var graph = new ObjectDescriptor(value, actualType, staticType); - void NestedObjectSerializer(object? v, Type? t) => SerializeValue(emitter, v, t); + void NestedObjectSerializer(object? v, Type? t) + { + SerializeValue(emitter, v, t); + } var preProcessingPhaseObjectGraphVisitors = preProcessingPhaseObjectGraphVisitorFactories.BuildComponentList(typeConverters); foreach (var visitor in preProcessingPhaseObjectGraphVisitors) diff --git a/YamlDotNet/Serialization/Utilities/TypeConverterCache.cs b/YamlDotNet/Serialization/Utilities/TypeConverterCache.cs index 288a08d44..27516082d 100644 --- a/YamlDotNet/Serialization/Utilities/TypeConverterCache.cs +++ b/YamlDotNet/Serialization/Utilities/TypeConverterCache.cs @@ -36,7 +36,7 @@ internal sealed class TypeConverterCache private readonly IYamlTypeConverter[] typeConverters; private readonly ConcurrentDictionary cache = new(); - public TypeConverterCache(IEnumerable? typeConverters) : this(typeConverters?.ToArray() ?? Array.Empty()) + public TypeConverterCache(IEnumerable? typeConverters) : this(typeConverters?.ToArray() ?? []) { } diff --git a/YamlDotNet/Serialization/YamlAttributeOverrides.cs b/YamlDotNet/Serialization/YamlAttributeOverrides.cs index efd82a15c..de3d7541b 100644 --- a/YamlDotNet/Serialization/YamlAttributeOverrides.cs +++ b/YamlDotNet/Serialization/YamlAttributeOverrides.cs @@ -23,6 +23,8 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Linq.Expressions; +using YamlDotNet.Helpers; using HashCode = YamlDotNet.Core.HashCode; namespace YamlDotNet.Serialization @@ -32,7 +34,7 @@ namespace YamlDotNet.Serialization /// public sealed partial class YamlAttributeOverrides { - private struct AttributeKey + private readonly struct AttributeKey { public readonly Type AttributeType; public readonly string PropertyName; @@ -177,13 +179,9 @@ public YamlAttributeOverrides Clone() } } -#if !NET20 namespace YamlDotNet.Serialization { - using System.Linq.Expressions; - using YamlDotNet.Helpers; - - partial class YamlAttributeOverrides + public partial class YamlAttributeOverrides { /// /// Adds a Member Attribute Override @@ -195,4 +193,3 @@ public void Add(Expression> propertyAccessor, Attri } } } -#endif diff --git a/YamlDotNet/Serialization/YamlSerializable.cs b/YamlDotNet/Serialization/YamlSerializable.cs index 1a4d59c59..0eeddede2 100644 --- a/YamlDotNet/Serialization/YamlSerializable.cs +++ b/YamlDotNet/Serialization/YamlSerializable.cs @@ -41,7 +41,9 @@ public YamlSerializableAttribute() /// Use this constructor if the attribute is placed on the . /// /// The type for which to include static code generation. +#pragma warning disable IDE0060 public YamlSerializableAttribute(Type serializableType) +#pragma warning restore IDE0060 { } }