diff --git a/Directory.Packages.props b/Directory.Packages.props index c23f4025..f6500990 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,13 +7,13 @@ - - + + - + diff --git a/YamlDotNet.Test/Core/EmitterTests.cs b/YamlDotNet.Test/Core/EmitterTests.cs index 9b28bb2a..354ce9e9 100644 --- a/YamlDotNet.Test/Core/EmitterTests.cs +++ b/YamlDotNet.Test/Core/EmitterTests.cs @@ -57,10 +57,11 @@ public void CompareOriginalAndEmittedText(string filename) var emittedText = EmittedTextFrom(originalEvents); var emittedEvents = ParsingEventsOf(emittedText); - emittedEvents.ShouldAllBeEquivalentTo(originalEvents, - opt => opt.Excluding(@event => @event.Start) - .Excluding(@event => @event.End) - .Excluding((ParsingEvent @event) => ((DocumentEnd)@event).IsImplicit)); + emittedEvents.Should().BeEquivalentTo(originalEvents, opt => opt + .Excluding(@event => @event.Start) + .Excluding(@event => @event.End) + .Excluding(@event => ((DocumentEnd)@event).IsImplicit) + ); } private IList ParsingEventsOf(string text) diff --git a/YamlDotNet.Test/Core/InsertionQueueTests.cs b/YamlDotNet.Test/Core/InsertionQueueTests.cs index 6cc49c5a..c50c1951 100644 --- a/YamlDotNet.Test/Core/InsertionQueueTests.cs +++ b/YamlDotNet.Test/Core/InsertionQueueTests.cs @@ -267,7 +267,7 @@ public void ShouldThrowExceptionWhenDequeuingEmptyContainer() Action action = () => queue.Dequeue(); - action.ShouldThrow(); + action.Should().Throw(); } [Fact] @@ -279,7 +279,7 @@ public void ShouldThrowExceptionWhenDequeuingContainerThatBecomesEmpty() queue.Dequeue(); Action action = () => queue.Dequeue(); - action.ShouldThrow(); + action.Should().Throw(); } [Fact] @@ -314,7 +314,7 @@ public void ShouldThrowExceptionWhenDequeuingAfterInserting() PerformTimes(2, queue.Dequeue); Action action = () => queue.Dequeue(); - action.ShouldThrow(); + action.Should().Throw(); } [Fact] diff --git a/YamlDotNet.Test/Core/LookAheadBufferTests.cs b/YamlDotNet.Test/Core/LookAheadBufferTests.cs index 16fc4d31..80f1209d 100644 --- a/YamlDotNet.Test/Core/LookAheadBufferTests.cs +++ b/YamlDotNet.Test/Core/LookAheadBufferTests.cs @@ -206,7 +206,7 @@ public void ShouldThrowWhenSkippingBeyondCurrentBuffer() buffer.Peek(3); Action action = () => buffer.Skip(5); - action.ShouldThrow(); + action.Should().Throw(); } private static LookAheadBuffer CreateBuffer(TextReader reader, int capacity) diff --git a/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs b/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs index 840c75a2..ea6d6d58 100644 --- a/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs +++ b/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs @@ -29,7 +29,6 @@ using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.RepresentationModel; -using YamlDotNet.Serialization.Schemas; namespace YamlDotNet.Test.RepresentationModel { @@ -57,7 +56,7 @@ public void AccessingAllNodesOnInfinitelyRecursiveDocumentThrows(string yaml) var accessAllNodes = new Action(() => stream.Documents.Single().AllNodes.ToList()); - accessAllNodes.ShouldThrow("because the document is infinitely recursive."); + accessAllNodes.Should().Throw("because the document is infinitely recursive."); } [Theory] diff --git a/YamlDotNet.Test/Serialization/BufferedDeserialization/KeyValueTypeDiscriminatorTests.cs b/YamlDotNet.Test/Serialization/BufferedDeserialization/KeyValueTypeDiscriminatorTests.cs index 262e084c..9b71af79 100644 --- a/YamlDotNet.Test/Serialization/BufferedDeserialization/KeyValueTypeDiscriminatorTests.cs +++ b/YamlDotNet.Test/Serialization/BufferedDeserialization/KeyValueTypeDiscriminatorTests.cs @@ -21,10 +21,8 @@ using System; using System.Collections.Generic; -using System.Linq; using FluentAssertions; using Xunit; -using YamlDotNet.Core; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; diff --git a/YamlDotNet.Test/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerTests.cs b/YamlDotNet.Test/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerTests.cs index 6550a253..d19495d4 100644 --- a/YamlDotNet.Test/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerTests.cs +++ b/YamlDotNet.Test/Serialization/BufferedDeserialization/TypeDiscriminatingNodeDeserializerTests.cs @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.Linq; using FluentAssertions; using Xunit; using YamlDotNet.Core; @@ -47,10 +46,10 @@ public void TypeDiscriminatingNodeDeserializer_ThrowsWhen_MaxDepthExceeded() Action act = () => bufferedDeserializer.Deserialize(KubernetesServiceYaml); act - .ShouldThrow() + .Should().Throw() .WithMessage("Failed to buffer yaml node") .WithInnerException() - .Where(e => e.InnerException.Message.Contains("Parser buffer exceeded max depth")); + .WithMessage("Parser buffer exceeded max depth*"); } [Fact] @@ -68,10 +67,10 @@ public void TypeDiscriminatingNodeDeserializer_ThrowsWhen_MaxLengthExceeded() Action act = () => bufferedDeserializer.Deserialize(KubernetesServiceYaml); act - .ShouldThrow() + .Should().Throw() .WithMessage("Failed to buffer yaml node") .WithInnerException() - .Where(e => e.InnerException.Message.Contains("Parser buffer exceeded max length")); + .WithMessage("Parser buffer exceeded max length*"); } public const string KubernetesServiceYaml = @" diff --git a/YamlDotNet.Test/Serialization/BufferedDeserialization/UniqueKeyTypeDiscriminatorTests.cs b/YamlDotNet.Test/Serialization/BufferedDeserialization/UniqueKeyTypeDiscriminatorTests.cs index d9978a5d..ceb0b03f 100644 --- a/YamlDotNet.Test/Serialization/BufferedDeserialization/UniqueKeyTypeDiscriminatorTests.cs +++ b/YamlDotNet.Test/Serialization/BufferedDeserialization/UniqueKeyTypeDiscriminatorTests.cs @@ -21,10 +21,8 @@ using System; using System.Collections.Generic; -using System.Linq; using FluentAssertions; using Xunit; -using YamlDotNet.Core; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; diff --git a/YamlDotNet.Test/Serialization/DateOnlyConverterTests.cs b/YamlDotNet.Test/Serialization/DateOnlyConverterTests.cs index 036bfebe..4e21fcd5 100644 --- a/YamlDotNet.Test/Serialization/DateOnlyConverterTests.cs +++ b/YamlDotNet.Test/Serialization/DateOnlyConverterTests.cs @@ -75,7 +75,7 @@ public void Given_Yaml_WithInvalidDateTimeFormat_WithDefaultParameter_ReadYaml_S Action action = () => { converter.ReadYaml(parser, typeof(DateOnly), null); }; - action.ShouldThrow(); + action.Should().Throw(); } /// diff --git a/YamlDotNet.Test/Serialization/DateTime8601ConverterTests.cs b/YamlDotNet.Test/Serialization/DateTime8601ConverterTests.cs index 743c55a6..9102e09e 100644 --- a/YamlDotNet.Test/Serialization/DateTime8601ConverterTests.cs +++ b/YamlDotNet.Test/Serialization/DateTime8601ConverterTests.cs @@ -20,11 +20,6 @@ // SOFTWARE. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using FakeItEasy; using Xunit; using YamlDotNet.Core; using YamlDotNet.Serialization; diff --git a/YamlDotNet.Test/Serialization/DateTimeConverterTests.cs b/YamlDotNet.Test/Serialization/DateTimeConverterTests.cs index bb741250..df91143b 100644 --- a/YamlDotNet.Test/Serialization/DateTimeConverterTests.cs +++ b/YamlDotNet.Test/Serialization/DateTimeConverterTests.cs @@ -74,7 +74,7 @@ public void Given_Yaml_WithInvalidDateTimeFormat_WithDefaultParameters_ReadYaml_ Action action = () => { converter.ReadYaml(parser, typeof(DateTime), null); }; - action.ShouldThrow(); + action.Should().Throw(); } /// diff --git a/YamlDotNet.Test/Serialization/DateTimeOffsetConverterTests.cs b/YamlDotNet.Test/Serialization/DateTimeOffsetConverterTests.cs index cafe0817..45067d1a 100644 --- a/YamlDotNet.Test/Serialization/DateTimeOffsetConverterTests.cs +++ b/YamlDotNet.Test/Serialization/DateTimeOffsetConverterTests.cs @@ -66,7 +66,7 @@ public void InvalidFormatThrowsException() Action action = () => { converter.ReadYaml(parser, typeof(DateTimeOffset), null); }; - action.ShouldThrow(); + action.Should().Throw(); } [Fact] diff --git a/YamlDotNet.Test/Serialization/DeserializerTest.cs b/YamlDotNet.Test/Serialization/DeserializerTest.cs index 618a4b86..fc49ae52 100644 --- a/YamlDotNet.Test/Serialization/DeserializerTest.cs +++ b/YamlDotNet.Test/Serialization/DeserializerTest.cs @@ -301,14 +301,14 @@ public void DeserializeWithDuplicateKeyChecking_YamlWithDuplicateKeys_ThrowsYaml .Build(); Action act = () => sut.Deserialize(yaml); - act.ShouldThrow("Because there are duplicate name keys with concrete class"); + act.Should().Throw("Because there are duplicate name keys with concrete class"); act = () => sut.Deserialize>(yaml); - act.ShouldThrow("Because there are duplicate name keys with dictionary"); + act.Should().Throw("Because there are duplicate name keys with dictionary"); var stream = Yaml.ReaderFrom("backreference.yaml"); var parser = new MergingParser(new Parser(stream)); act = () => sut.Deserialize>>(parser); - act.ShouldThrow("Because there are duplicate name keys with merging parser"); + act.Should().Throw("Because there are duplicate name keys with merging parser"); } [Fact] @@ -325,14 +325,14 @@ public void DeserializeWithoutDuplicateKeyChecking_YamlWithDuplicateKeys_DoesNot .Build(); Action act = () => sut.Deserialize(yaml); - act.ShouldNotThrow("Because duplicate key checking is not enabled"); + act.Should().NotThrow("Because duplicate key checking is not enabled"); act = () => sut.Deserialize>(yaml); - act.ShouldNotThrow("Because duplicate key checking is not enabled"); + act.Should().NotThrow("Because duplicate key checking is not enabled"); var stream = Yaml.ReaderFrom("backreference.yaml"); var parser = new MergingParser(new Parser(stream)); act = () => sut.Deserialize>>(parser); - act.ShouldNotThrow("Because duplicate key checking is not enabled"); + act.Should().NotThrow("Because duplicate key checking is not enabled"); } [Fact] diff --git a/YamlDotNet.Test/Serialization/HiddenPropertyTests.cs b/YamlDotNet.Test/Serialization/HiddenPropertyTests.cs index b8e71369..91222a2b 100644 --- a/YamlDotNet.Test/Serialization/HiddenPropertyTests.cs +++ b/YamlDotNet.Test/Serialization/HiddenPropertyTests.cs @@ -94,7 +94,7 @@ public void TestDuplicate() .Build(); Action action = () => { d.Deserialize>(yaml); }; - action.ShouldThrow(); + action.Should().Throw(); } } } diff --git a/YamlDotNet.Test/Serialization/SerializationTests.cs b/YamlDotNet.Test/Serialization/SerializationTests.cs index 6325ec90..7bff67b1 100644 --- a/YamlDotNet.Test/Serialization/SerializationTests.cs +++ b/YamlDotNet.Test/Serialization/SerializationTests.cs @@ -35,7 +35,6 @@ using System.Threading; using FakeItEasy; using FluentAssertions; -using FluentAssertions.Common; using Xunit; using YamlDotNet.Core; using YamlDotNet.Core.Events; @@ -107,7 +106,7 @@ public void DeserializeScalarBooleanThrowsWhenInvalid() { Action action = () => Deserializer.Deserialize(UsingReaderFor("not-a-boolean")); - action.ShouldThrow().WithInnerException(); + action.Should().Throw().WithInnerException(); } [Fact] @@ -217,7 +216,7 @@ public void SerializeCircularReference() Action action = () => SerializerBuilder.EnsureRoundtrip().Build().Serialize(new StringWriter(), obj, typeof(CircularReference)); - action.ShouldNotThrow(); + action.Should().NotThrow(); } [Fact] @@ -225,7 +224,7 @@ public void DeserializeIncompleteDirective() { Action action = () => Deserializer.Deserialize(UsingReaderFor("%Y")); - action.ShouldThrow() + action.Should().Throw() .WithMessage("While scanning a directive, found unexpected end of stream."); } @@ -234,7 +233,7 @@ public void DeserializeSkippedReservedDirective() { Action action = () => Deserializer.Deserialize(UsingReaderFor("%Y ")); - action.ShouldNotThrow(); + action.Should().NotThrow(); } [Fact] @@ -247,7 +246,7 @@ public void DeserializeCustomTags() result.Should().BeOfType().And .Subject.As() - .ShouldBeEquivalentTo(new { X = 10, Y = 20 }, o => o.ExcludingMissingMembers()); + .Should().BeEquivalentTo(new { X = 10, Y = 20 }, o => o.ExcludingMissingMembers()); } [Fact] @@ -365,7 +364,7 @@ public void DeserializationFailsForUndefinedForwardReferences() Action action = () => Deserializer.Deserialize(UsingReaderFor(text)); - action.ShouldThrow(); + action.Should().Throw(); } [Fact] @@ -384,7 +383,7 @@ public void RoundtripObject() .Build() ); - result.ShouldBeEquivalentTo(obj); + result.Should().BeEquivalentTo(obj); } [Fact] @@ -403,7 +402,7 @@ public void RoundtripObjectWithDefaults() .Build() ); - result.ShouldBeEquivalentTo(obj); + result.Should().BeEquivalentTo(obj); } [Fact] @@ -508,7 +507,7 @@ public void RoundtripDerivedClass() result.SomeScalar.Should().Be("Hello"); result.RegularBase.Should().BeOfType().And - .Subject.As().ShouldBeEquivalentTo(new { ChildProp = "bar" }, o => o.ExcludingMissingMembers()); + .Subject.As().Should().BeEquivalentTo(new { ChildProp = "bar" }, o => o.ExcludingMissingMembers()); } [Fact] @@ -532,7 +531,7 @@ public void RoundtripDerivedClassWithSerializeAs() ); result.BaseWithSerializeAs.Should().BeOfType().And - .Subject.As().ShouldBeEquivalentTo(new { ParentProp = "foo" }, o => o.ExcludingMissingMembers()); + .Subject.As().Should().BeEquivalentTo(new { ParentProp = "foo" }, o => o.ExcludingMissingMembers()); } [Fact] @@ -553,7 +552,7 @@ public void RoundtripInterfaceProperties() var result = DoRoundtripFromObjectTo(obj); result.Derived.Should().BeOfType().And - .Subject.As().ShouldBeEquivalentTo(new { BaseProperty = "foo", DerivedProperty = "bar" }, o => o.ExcludingMissingMembers()); + .Subject.As().Should().BeEquivalentTo(new { BaseProperty = "foo", DerivedProperty = "bar" }, o => o.ExcludingMissingMembers()); } [Fact] @@ -603,8 +602,7 @@ public void DeserializeList() var result = Deserializer.Deserialize(stream); - result.Should().BeAssignableTo().And - .Subject.As().Should().Equal(new[] { "one", "two", "three" }); + result.Should().BeEquivalentTo(new[] { "one", "two", "three" }); } [Fact] @@ -705,7 +703,7 @@ public void DeserializeListOfDictionaries() var result = Deserializer.Deserialize>>(stream); - result.ShouldBeEquivalentTo(new[] { + result.Should().BeEquivalentTo(new[] { new Dictionary { { "connection", "conn1" }, { "path", "path1" } @@ -730,8 +728,8 @@ public void DeserializeTwoDocuments() var one = Deserializer.Deserialize(reader); var two = Deserializer.Deserialize(reader); - one.ShouldBeEquivalentTo(new { aaa = "111" }); - two.ShouldBeEquivalentTo(new { aaa = "222" }); + one.Should().BeEquivalentTo(new { aaa = "111" }); + two.Should().BeEquivalentTo(new { aaa = "222" }); } [Fact] @@ -752,9 +750,9 @@ public void DeserializeThreeDocuments() var three = Deserializer.Deserialize(reader); reader.Accept(out var _).Should().BeTrue("reader should have reached StreamEnd"); - one.ShouldBeEquivalentTo(new { aaa = "111" }); - two.ShouldBeEquivalentTo(new { aaa = "222" }); - three.ShouldBeEquivalentTo(new { aaa = "333" }); + one.Should().BeEquivalentTo(new { aaa = "111" }); + two.Should().BeEquivalentTo(new { aaa = "222" }); + three.Should().BeEquivalentTo(new { aaa = "333" }); } [Fact] @@ -1128,7 +1126,7 @@ public void SerializingAGenericDictionaryShouldNotThrowTargetException() Action action = () => Serializer.Serialize(new StringWriter(), obj); - action.ShouldNotThrow(); + action.Should().NotThrow(); } [Fact] @@ -2027,7 +2025,7 @@ public void AliasBeforeAnchorCannotBeDeserialized() b: &anchor1 test0 c: *anchor1"); - action.ShouldThrow(); + action.Should().Throw(); } [Fact] @@ -2560,7 +2558,7 @@ public void NamingConventionAppliedToEnum() var serializer = new SerializerBuilder().WithEnumNamingConvention(CamelCaseNamingConvention.Instance).Build(); ScalarStyle style = ScalarStyle.Plain; var serialized = serializer.Serialize(style); - Assert.Equal("plain", serialized.RemoveNewLines()); + Assert.Equal("plain", serialized.Replace("\r\n", "").Replace("\n", "")); } [Fact] diff --git a/YamlDotNet.Test/Serialization/TimeOnlyConverterTests.cs b/YamlDotNet.Test/Serialization/TimeOnlyConverterTests.cs index 947cd137..9428f965 100644 --- a/YamlDotNet.Test/Serialization/TimeOnlyConverterTests.cs +++ b/YamlDotNet.Test/Serialization/TimeOnlyConverterTests.cs @@ -75,7 +75,7 @@ public void Given_Yaml_WithInvalidDateTimeFormat_WithDefaultParameters_ReadYaml_ Action action = () => { converter.ReadYaml(parser, typeof(TimeOnly), null); }; - action.ShouldThrow(); + action.Should().Throw(); } /// diff --git a/YamlDotNet.Test/Serialization/TypeConverterAttributeTests.cs b/YamlDotNet.Test/Serialization/TypeConverterAttributeTests.cs index 2da834e8..88539c8c 100644 --- a/YamlDotNet.Test/Serialization/TypeConverterAttributeTests.cs +++ b/YamlDotNet.Test/Serialization/TypeConverterAttributeTests.cs @@ -20,10 +20,6 @@ // SOFTWARE. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Xunit; using YamlDotNet.Core; using YamlDotNet.Core.Events; diff --git a/YamlDotNet.Test/Serialization/YamlCommentTests.cs b/YamlDotNet.Test/Serialization/YamlCommentTests.cs index eedd1842..14403a26 100644 --- a/YamlDotNet.Test/Serialization/YamlCommentTests.cs +++ b/YamlDotNet.Test/Serialization/YamlCommentTests.cs @@ -50,7 +50,7 @@ public void SerializationWithBlockComments() var deserializer = new Deserializer(); Action action = () => deserializer.Deserialize(result); - action.ShouldNotThrow(); + action.Should().NotThrow(); var lines = SplitByLines(result); @@ -69,7 +69,7 @@ public void SerializationWithBlockComments_Multiline() var deserializer = new Deserializer(); Action action = () => deserializer.Deserialize(result); - action.ShouldNotThrow(); + action.Should().NotThrow(); var lines = SplitByLines(result); @@ -86,7 +86,7 @@ public void SerializationWithBlockComments_NullValue() { var serializer = new Serializer(); Action action = () => serializer.Serialize(new NullComment()); - action.ShouldNotThrow(); + action.Should().NotThrow(); } #endregion @@ -102,7 +102,7 @@ public void SerializationWithBlockComments_IndentedInSequence() var deserializer = new Deserializer(); Action action = () => deserializer.Deserialize(result); - action.ShouldNotThrow(); + action.Should().NotThrow(); var lines = SplitByLines(result); var indent = GetIndent(1); @@ -128,7 +128,7 @@ public void SerializationWithBlockComments_IndentedInBlock() var deserializer = new Deserializer(); Action action = () => deserializer.Deserialize(result); - action.ShouldNotThrow(); + action.Should().NotThrow(); var lines = SplitByLines(result); var indent1 = GetIndent(1); @@ -159,7 +159,7 @@ public void SerializationWithBlockComments_IndentedInBlockAndSequence() var deserializer = new Deserializer(); Action action = () => deserializer.Deserialize(result); - action.ShouldNotThrow(); + action.Should().NotThrow(); var lines = SplitByLines(result); var indent1 = GetIndent(1); @@ -195,7 +195,7 @@ public void SerializationWithBlockComments_IndentedInBlockAndSequence_WithFlowMa var deserializer = new Deserializer(); Action action = () => deserializer.Deserialize(result); - action.ShouldNotThrow(); + action.Should().NotThrow(); var lines = SplitByLines(result); var indent1 = GetIndent(1); diff --git a/YamlDotNet.Test/YamlTests.cs b/YamlDotNet.Test/YamlTests.cs index 14eebb4a..409388bd 100644 --- a/YamlDotNet.Test/YamlTests.cs +++ b/YamlDotNet.Test/YamlTests.cs @@ -110,7 +110,7 @@ public void TextThrowsArgumentOutOfRangeExceptionForInsuffientIndentation() #endif Action act = () => Yaml.Text(BadlyIndentedLines); - act.ShouldThrowExactly().WithMessage(expectedMessage); + act.Should().ThrowExactly().WithMessage(expectedMessage); } } } 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