diff --git a/YamlDotNet/Core/Constants.cs b/YamlDotNet/Core/Constants.cs index 7e907327..8ac19e9b 100644 --- a/YamlDotNet/Core/Constants.cs +++ b/YamlDotNet/Core/Constants.cs @@ -29,10 +29,10 @@ namespace YamlDotNet.Core public static class Constants { public static readonly TagDirective[] DefaultTagDirectives = - { + [ new TagDirective("!", "!"), new TagDirective("!!", "tag:yaml.org,2002:") - }; + ]; public const int MajorVersion = 1; public const int MinorVersion = 3; diff --git a/YamlDotNet/Core/Emitter.cs b/YamlDotNet/Core/Emitter.cs index 333043c7..01824d10 100644 --- a/YamlDotNet/Core/Emitter.cs +++ b/YamlDotNet/Core/Emitter.cs @@ -56,7 +56,7 @@ public class Emitter : IEmitter private readonly Stack states = new Stack(); private readonly Queue events = new Queue(); private readonly Stack indents = new Stack(); - private readonly TagDirectiveCollection tagDirectives = new TagDirectiveCollection(); + private readonly TagDirectiveCollection tagDirectives = []; private int indent; private int flowLevel; private bool isMappingContext; diff --git a/YamlDotNet/Core/MergingParser.cs b/YamlDotNet/Core/MergingParser.cs index 7a435da7..14c59393 100644 --- a/YamlDotNet/Core/MergingParser.cs +++ b/YamlDotNet/Core/MergingParser.cs @@ -173,9 +173,9 @@ private sealed class ParsingEventCollection : IEnumerable(); - deleted = new HashSet>(); - references = new Dictionary>(); + events = []; + deleted = []; + references = []; } public void AddAfter(LinkedListNode node, IEnumerable items) diff --git a/YamlDotNet/Core/Parser.cs b/YamlDotNet/Core/Parser.cs index d89a1a85..db453457 100644 --- a/YamlDotNet/Core/Parser.cs +++ b/YamlDotNet/Core/Parser.cs @@ -36,7 +36,7 @@ namespace YamlDotNet.Core public class Parser : IParser { private readonly Stack states = new Stack(); - private readonly TagDirectiveCollection tagDirectives = new TagDirectiveCollection(); + private readonly TagDirectiveCollection tagDirectives = []; private ParserState state; private readonly IScanner scanner; diff --git a/YamlDotNet/Helpers/FsharpHelper.cs b/YamlDotNet/Helpers/FsharpHelper.cs index 52978e4b..6339a680 100644 --- a/YamlDotNet/Helpers/FsharpHelper.cs +++ b/YamlDotNet/Helpers/FsharpHelper.cs @@ -73,7 +73,7 @@ public static bool IsFsharpListType(Type t) .GetType("Microsoft.FSharp.Collections.ListModule") .GetMethod("OfArray") .MakeGenericMethod(itemsType) - .Invoke(null, new[] { arr }); + .Invoke(null, [arr]); return fsharpList; } diff --git a/YamlDotNet/Helpers/OrderedDictionary.cs b/YamlDotNet/Helpers/OrderedDictionary.cs index 8b28348d..9d1ab796 100644 --- a/YamlDotNet/Helpers/OrderedDictionary.cs +++ b/YamlDotNet/Helpers/OrderedDictionary.cs @@ -76,7 +76,7 @@ public OrderedDictionary() : this(EqualityComparer.Default) public OrderedDictionary(IEqualityComparer comparer) { - list = new List>(); + list = []; dictionary = new Dictionary(comparer); this.comparer = comparer; } @@ -192,7 +192,7 @@ public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) => internal void OnDeserializedMethod(StreamingContext context) { // Reconstruct the dictionary from the serialized list - dictionary = new Dictionary(); + dictionary = []; foreach (var kvp in list) { dictionary[kvp.Key] = kvp.Value; diff --git a/YamlDotNet/RepresentationModel/DocumentLoadingState.cs b/YamlDotNet/RepresentationModel/DocumentLoadingState.cs index 036b5514..be41779b 100644 --- a/YamlDotNet/RepresentationModel/DocumentLoadingState.cs +++ b/YamlDotNet/RepresentationModel/DocumentLoadingState.cs @@ -31,8 +31,8 @@ namespace YamlDotNet.RepresentationModel /// internal class DocumentLoadingState { - private readonly Dictionary anchors = new Dictionary(); - private readonly List nodesWithUnresolvedAliases = new List(); + private readonly Dictionary anchors = []; + private readonly List nodesWithUnresolvedAliases = []; /// /// Adds the specified node to the anchor list. diff --git a/YamlDotNet/RepresentationModel/EmitterState.cs b/YamlDotNet/RepresentationModel/EmitterState.cs index 996c94c6..e3d444bf 100644 --- a/YamlDotNet/RepresentationModel/EmitterState.cs +++ b/YamlDotNet/RepresentationModel/EmitterState.cs @@ -33,6 +33,6 @@ internal class EmitterState /// Gets the already emitted anchors. /// /// The emitted anchors. - public HashSet EmittedAnchors { get; } = new HashSet(); + public HashSet EmittedAnchors { get; } = []; } } diff --git a/YamlDotNet/RepresentationModel/YamlDocument.cs b/YamlDotNet/RepresentationModel/YamlDocument.cs index 9c2ce078..4dbc16ee 100644 --- a/YamlDotNet/RepresentationModel/YamlDocument.cs +++ b/YamlDotNet/RepresentationModel/YamlDocument.cs @@ -90,11 +90,11 @@ internal YamlDocument(IParser parser) /// private class AnchorAssigningVisitor : YamlVisitorBase { - private readonly HashSet existingAnchors = new HashSet(); + private readonly HashSet existingAnchors = []; /// /// Key: Node, Value: IsDuplicate /// - private readonly Dictionary visitedNodes = new Dictionary(); + private readonly Dictionary visitedNodes = []; public void AssignAnchors(YamlDocument document) { diff --git a/YamlDotNet/RepresentationModel/YamlMappingNode.cs b/YamlDotNet/RepresentationModel/YamlMappingNode.cs index 85c22a73..f22380c1 100644 --- a/YamlDotNet/RepresentationModel/YamlMappingNode.cs +++ b/YamlDotNet/RepresentationModel/YamlMappingNode.cs @@ -36,7 +36,7 @@ namespace YamlDotNet.RepresentationModel /// public sealed class YamlMappingNode : YamlNode, IEnumerable>, IYamlConvertible { - private readonly OrderedDictionary children = new OrderedDictionary(); + private readonly OrderedDictionary children = []; /// /// Gets the children of the current node. @@ -196,13 +196,13 @@ internal override void ResolveAliases(DocumentLoadingState state) { if (entry.Key is YamlAliasNode) { - keysToUpdate ??= new Dictionary(); + keysToUpdate ??= []; // 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) { - valuesToUpdate ??= new Dictionary(); + valuesToUpdate ??= []; // 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/YamlSequenceNode.cs b/YamlDotNet/RepresentationModel/YamlSequenceNode.cs index 3d790a6c..9526a50d 100644 --- a/YamlDotNet/RepresentationModel/YamlSequenceNode.cs +++ b/YamlDotNet/RepresentationModel/YamlSequenceNode.cs @@ -36,7 +36,7 @@ namespace YamlDotNet.RepresentationModel [DebuggerDisplay("Count = {children.Count}")] public sealed class YamlSequenceNode : YamlNode, IEnumerable, IYamlConvertible { - private readonly List children = new List(); + private readonly List children = []; /// /// Gets the collection of child nodes. diff --git a/YamlDotNet/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerOptions.cs b/YamlDotNet/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerOptions.cs index 7cec41d3..a0289b96 100644 --- a/YamlDotNet/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerOptions.cs +++ b/YamlDotNet/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerOptions.cs @@ -30,7 +30,7 @@ namespace YamlDotNet.Serialization.BufferedDeserialization { public class TypeDiscriminatingNodeDeserializerOptions : ITypeDiscriminatingNodeDeserializerOptions { - internal readonly List discriminators = new List(); + internal readonly List discriminators = []; /// /// Adds an to be checked by the TypeDiscriminatingNodeDeserializer. @@ -64,4 +64,4 @@ public void AddUniqueKeyTypeDiscriminator(IDictionary uniqueKey this.discriminators.Add(new UniqueKeyTypeDiscriminator(typeof(T), uniqueKeyTypeMapping)); } } -} \ No newline at end of file +} diff --git a/YamlDotNet/Serialization/BuilderSkeleton.cs b/YamlDotNet/Serialization/BuilderSkeleton.cs index fdc5c01f..a19d2414 100755 --- a/YamlDotNet/Serialization/BuilderSkeleton.cs +++ b/YamlDotNet/Serialization/BuilderSkeleton.cs @@ -58,7 +58,7 @@ internal BuilderSkeleton(ITypeResolver typeResolver) { typeof(SystemTypeConverter), _ => new SystemTypeConverter() } }; - typeInspectorFactories = new LazyComponentRegistrationList(); + typeInspectorFactories = []; this.typeResolver = typeResolver ?? throw new ArgumentNullException(nameof(typeResolver)); settings = new Settings(); } diff --git a/YamlDotNet/Serialization/DeserializerBuilder.cs b/YamlDotNet/Serialization/DeserializerBuilder.cs index e3b47609..3c0f27b7 100755 --- a/YamlDotNet/Serialization/DeserializerBuilder.cs +++ b/YamlDotNet/Serialization/DeserializerBuilder.cs @@ -71,7 +71,7 @@ public sealed class DeserializerBuilder : BuilderSkeleton public DeserializerBuilder() : base(new StaticTypeResolver()) { - typeMappings = new Dictionary(); + typeMappings = []; objectFactory = new Lazy(() => new DefaultObjectFactory(typeMappings, settings), true); tagMappings = new Dictionary diff --git a/YamlDotNet/Serialization/LazyComponentRegistrationList.cs b/YamlDotNet/Serialization/LazyComponentRegistrationList.cs index 9e4c0eba..03fb2cf7 100644 --- a/YamlDotNet/Serialization/LazyComponentRegistrationList.cs +++ b/YamlDotNet/Serialization/LazyComponentRegistrationList.cs @@ -28,7 +28,7 @@ namespace YamlDotNet.Serialization { internal sealed class LazyComponentRegistrationList : IEnumerable> { - private readonly List entries = new List(); + private readonly List entries = []; public LazyComponentRegistrationList Clone() { diff --git a/YamlDotNet/Serialization/ObjectGraphVisitors/AnchorAssigner.cs b/YamlDotNet/Serialization/ObjectGraphVisitors/AnchorAssigner.cs index 1a7dd648..5a161b6c 100644 --- a/YamlDotNet/Serialization/ObjectGraphVisitors/AnchorAssigner.cs +++ b/YamlDotNet/Serialization/ObjectGraphVisitors/AnchorAssigner.cs @@ -33,7 +33,7 @@ private class AnchorAssignment public AnchorName Anchor; } - private readonly Dictionary assignments = new Dictionary(); + private readonly Dictionary assignments = []; private uint nextId; public AnchorAssigner(IEnumerable typeConverters) diff --git a/YamlDotNet/Serialization/ObjectGraphVisitors/AnchorAssigningObjectGraphVisitor.cs b/YamlDotNet/Serialization/ObjectGraphVisitors/AnchorAssigningObjectGraphVisitor.cs index 7c69470a..930b21bf 100644 --- a/YamlDotNet/Serialization/ObjectGraphVisitors/AnchorAssigningObjectGraphVisitor.cs +++ b/YamlDotNet/Serialization/ObjectGraphVisitors/AnchorAssigningObjectGraphVisitor.cs @@ -29,7 +29,7 @@ public sealed class AnchorAssigningObjectGraphVisitor : ChainedObjectGraphVisito { private readonly IEventEmitter eventEmitter; private readonly IAliasProvider aliasProvider; - private readonly HashSet emittedAliases = new HashSet(); + private readonly HashSet emittedAliases = []; public AnchorAssigningObjectGraphVisitor(IObjectGraphVisitor nextVisitor, IEventEmitter eventEmitter, IAliasProvider aliasProvider) : base(nextVisitor) diff --git a/YamlDotNet/Serialization/SerializerBuilder.cs b/YamlDotNet/Serialization/SerializerBuilder.cs index 10cfb969..bae3896d 100755 --- a/YamlDotNet/Serialization/SerializerBuilder.cs +++ b/YamlDotNet/Serialization/SerializerBuilder.cs @@ -55,7 +55,7 @@ public sealed class SerializerBuilder : BuilderSkeleton private readonly LazyComponentRegistrationList, IObjectGraphVisitor> preProcessingPhaseObjectGraphVisitorFactories; private readonly LazyComponentRegistrationList> emissionPhaseObjectGraphVisitorFactories; private readonly LazyComponentRegistrationList eventEmitterFactories; - private readonly Dictionary tagMappings = new Dictionary(); + private readonly Dictionary tagMappings = []; private readonly IObjectFactory objectFactory; private int maximumRecursion = 50; private EmitterSettings emitterSettings = EmitterSettings.Default; diff --git a/YamlDotNet/Serialization/StaticBuilderSkeleton.cs b/YamlDotNet/Serialization/StaticBuilderSkeleton.cs index 0ca4c939..62875359 100644 --- a/YamlDotNet/Serialization/StaticBuilderSkeleton.cs +++ b/YamlDotNet/Serialization/StaticBuilderSkeleton.cs @@ -50,7 +50,7 @@ internal StaticBuilderSkeleton(ITypeResolver typeResolver) { typeof(GuidConverter), _ => new GuidConverter(false) }, }; - typeInspectorFactories = new LazyComponentRegistrationList(); + typeInspectorFactories = []; this.typeResolver = typeResolver ?? throw new ArgumentNullException(nameof(typeResolver)); settings = new Settings(); } diff --git a/YamlDotNet/Serialization/StaticDeserializerBuilder.cs b/YamlDotNet/Serialization/StaticDeserializerBuilder.cs index d146a2e3..572e53c9 100644 --- a/YamlDotNet/Serialization/StaticDeserializerBuilder.cs +++ b/YamlDotNet/Serialization/StaticDeserializerBuilder.cs @@ -69,7 +69,7 @@ public StaticDeserializerBuilder(StaticContext context) { this.context = context; factory = context.GetFactory(); - typeMappings = new Dictionary(); + typeMappings = []; tagMappings = new Dictionary { diff --git a/YamlDotNet/Serialization/StaticSerializerBuilder.cs b/YamlDotNet/Serialization/StaticSerializerBuilder.cs index f561cc9f..4c165fbc 100644 --- a/YamlDotNet/Serialization/StaticSerializerBuilder.cs +++ b/YamlDotNet/Serialization/StaticSerializerBuilder.cs @@ -52,7 +52,7 @@ public sealed class StaticSerializerBuilder : StaticBuilderSkeleton, IObjectGraphVisitor> preProcessingPhaseObjectGraphVisitorFactories; private readonly LazyComponentRegistrationList> emissionPhaseObjectGraphVisitorFactories; private readonly LazyComponentRegistrationList eventEmitterFactories; - private readonly Dictionary tagMappings = new Dictionary(); + private readonly Dictionary tagMappings = []; private int maximumRecursion = 50; private EmitterSettings emitterSettings = EmitterSettings.Default; private DefaultValuesHandling defaultValuesHandlingConfiguration = DefaultValuesHandling.Preserve; diff --git a/YamlDotNet/Serialization/StreamFragment.cs b/YamlDotNet/Serialization/StreamFragment.cs index 12d9de3e..632a0de9 100644 --- a/YamlDotNet/Serialization/StreamFragment.cs +++ b/YamlDotNet/Serialization/StreamFragment.cs @@ -32,7 +32,7 @@ namespace YamlDotNet.Serialization /// public sealed class StreamFragment : IYamlConvertible { - private readonly List events = new List(); + private readonly List events = []; /// /// Gets or sets the events. diff --git a/YamlDotNet/Serialization/TagMappings.cs b/YamlDotNet/Serialization/TagMappings.cs index 1749ab68..00b63cbc 100644 --- a/YamlDotNet/Serialization/TagMappings.cs +++ b/YamlDotNet/Serialization/TagMappings.cs @@ -36,7 +36,7 @@ public sealed class TagMappings /// public TagMappings() { - mappings = new Dictionary(); + mappings = []; } /// diff --git a/YamlDotNet/Serialization/Utilities/ObjectAnchorCollection.cs b/YamlDotNet/Serialization/Utilities/ObjectAnchorCollection.cs index b41660cc..4abde9d3 100644 --- a/YamlDotNet/Serialization/Utilities/ObjectAnchorCollection.cs +++ b/YamlDotNet/Serialization/Utilities/ObjectAnchorCollection.cs @@ -27,8 +27,8 @@ namespace YamlDotNet.Serialization.Utilities { internal sealed class ObjectAnchorCollection { - private readonly Dictionary objectsByAnchor = new Dictionary(); - private readonly Dictionary anchorsByObject = new Dictionary(); + private readonly Dictionary objectsByAnchor = []; + private readonly Dictionary anchorsByObject = []; /// /// Adds the specified anchor. diff --git a/YamlDotNet/Serialization/Utilities/SerializerState.cs b/YamlDotNet/Serialization/Utilities/SerializerState.cs index b3e67a1f..944af3ee 100644 --- a/YamlDotNet/Serialization/Utilities/SerializerState.cs +++ b/YamlDotNet/Serialization/Utilities/SerializerState.cs @@ -31,7 +31,7 @@ namespace YamlDotNet.Serialization.Utilities /// public sealed class SerializerState : IDisposable { - private readonly Dictionary items = new Dictionary(); + private readonly Dictionary items = []; public T Get() where T : class, new() diff --git a/YamlDotNet/Serialization/Utilities/TypeConverter.cs b/YamlDotNet/Serialization/Utilities/TypeConverter.cs index a20d07c2..ed2667db 100644 --- a/YamlDotNet/Serialization/Utilities/TypeConverter.cs +++ b/YamlDotNet/Serialization/Utilities/TypeConverter.cs @@ -180,7 +180,7 @@ public static T ChangeType(object? value, INamingConvention enumNamingConvent { try { - return method.Invoke(null, new[] { value }); + return method.Invoke(null, [value]); } catch (TargetInvocationException ex) { @@ -200,14 +200,14 @@ public static T ChangeType(object? value, INamingConvention enumNamingConvent var parseMethod = destinationType.GetPublicStaticMethod("Parse", typeof(string), typeof(IFormatProvider)); if (parseMethod != null) { - return parseMethod.Invoke(null, new object[] { value, culture }); + return parseMethod.Invoke(null, [value, culture]); } // Try with - public static T Parse(string) parseMethod = destinationType.GetPublicStaticMethod("Parse", typeof(string)); if (parseMethod != null) { - return parseMethod.Invoke(null, new object[] { value }); + return parseMethod.Invoke(null, [value]); } } catch (TargetInvocationException ex) diff --git a/YamlDotNet/Serialization/YamlAttributeOverrides.cs b/YamlDotNet/Serialization/YamlAttributeOverrides.cs index de3d7541..b71520c7 100644 --- a/YamlDotNet/Serialization/YamlAttributeOverrides.cs +++ b/YamlDotNet/Serialization/YamlAttributeOverrides.cs @@ -108,7 +108,7 @@ public int Matches(Type matchType) } } - private readonly Dictionary> overrides = new Dictionary>(); + private readonly Dictionary> overrides = []; [return: MaybeNull] public T GetAttribute(Type type, string member) where T : Attribute @@ -150,7 +150,7 @@ public void Add(Type type, string member, Attribute attribute) var attributeKey = new AttributeKey(attribute.GetType(), member); if (!overrides.TryGetValue(attributeKey, out var mappings)) { - mappings = new List(); + mappings = []; overrides.Add(attributeKey, mappings); } else if (mappings.Contains(mapping)) diff --git a/YamlDotNet/Serialization/YamlFormatter.cs b/YamlDotNet/Serialization/YamlFormatter.cs index 5addd4e5..de0e3586 100644 --- a/YamlDotNet/Serialization/YamlFormatter.cs +++ b/YamlDotNet/Serialization/YamlFormatter.cs @@ -32,12 +32,12 @@ public class YamlFormatter { CurrencyDecimalSeparator = ".", CurrencyGroupSeparator = "_", - CurrencyGroupSizes = new[] { 3 }, + CurrencyGroupSizes = [3], CurrencySymbol = string.Empty, CurrencyDecimalDigits = 99, NumberDecimalSeparator = ".", NumberGroupSeparator = "_", - NumberGroupSizes = new[] { 3 }, + NumberGroupSizes = [3], NumberDecimalDigits = 99, NaNSymbol = ".nan", PositiveInfinitySymbol = ".inf", diff --git a/YamlDotNet/YamlDotNet.csproj b/YamlDotNet/YamlDotNet.csproj index e76a80f0..292faae2 100644 --- a/YamlDotNet/YamlDotNet.csproj +++ b/YamlDotNet/YamlDotNet.csproj @@ -61,7 +61,6 @@ $(NoWarn);CA1725 $(NoWarn);CS1061;CA1016 - $(NoWarn);IDE0028 $(NoWarn);IDE0045 $(NoWarn);IDE0046 $(NoWarn);IDE0047 @@ -69,9 +68,7 @@ $(NoWarn);IDE0083 $(NoWarn);IDE0090 $(NoWarn);IDE0110 - $(NoWarn);IDE0251 $(NoWarn);IDE0290 - $(NoWarn);IDE0300