diff --git a/src/SharpYaml.Tests/ParserTests.cs b/src/SharpYaml.Tests/ParserTests.cs index 79ed31c..f6e4253 100644 --- a/src/SharpYaml.Tests/ParserTests.cs +++ b/src/SharpYaml.Tests/ParserTests.cs @@ -361,22 +361,22 @@ private void AssertEvent(ParsingEvent expected, ParsingEvent actual, int eventNu var value = property.GetValue(actual, null); var expectedValue = property.GetValue(expected, null); - if (expectedValue is IEnumerable && !(expectedValue is string)) + if (expectedValue is IEnumerable enumerable && !(expectedValue is string)) { Dump.Write("\t{0} = {{", property.Name); Dump.Write(string.Join(", ", (IEnumerable)value)); Dump.WriteLine("}"); - if (expectedValue is ICollection && value is ICollection) + if (expectedValue is ICollection expectedCollection && value is ICollection collection) { - var expectedCount = ((ICollection)expectedValue).Count; - var valueCount = ((ICollection)value).Count; + var expectedCount = expectedCollection.Count; + var valueCount = collection.Count; Assert.AreEqual(expectedCount, valueCount, "Compared size of collections in property {0} in parse event {1}", property.Name, eventNumber); } var values = ((IEnumerable)value).GetEnumerator(); - var expectedValues = ((IEnumerable)expectedValue).GetEnumerator(); + var expectedValues = enumerable.GetEnumerator(); while (expectedValues.MoveNext()) { Assert.True(values.MoveNext(), "Property {0} in parse event {1} had too few elements", property.Name, eventNumber); diff --git a/src/SharpYaml.Tests/SchemaTests.cs b/src/SharpYaml.Tests/SchemaTests.cs index 9195f05..9b8aa4a 100644 --- a/src/SharpYaml.Tests/SchemaTests.cs +++ b/src/SharpYaml.Tests/SchemaTests.cs @@ -150,9 +150,7 @@ public void TestCoreSchemaCommon(IYamlSchema schema) private void TryParse(IYamlSchema schema, string scalar, string expectedShortTag, object expectedValue) { - string tag; - object value; - Assert.True(schema.TryParse(new Scalar(scalar), true, out tag, out value)); + Assert.True(schema.TryParse(new Scalar(scalar), true, out var tag, out var value)); Assert.AreEqual(expectedShortTag, tag); Assert.AreEqual(expectedValue, value); } diff --git a/src/SharpYaml.Tests/Serialization/SerializationTests2.cs b/src/SharpYaml.Tests/Serialization/SerializationTests2.cs index f91e723..08d4216 100644 --- a/src/SharpYaml.Tests/Serialization/SerializationTests2.cs +++ b/src/SharpYaml.Tests/Serialization/SerializationTests2.cs @@ -1111,8 +1111,7 @@ public override KeyValuePair ReadDictionaryItem(ref ObjectContex public override void WriteDictionaryItem(ref ObjectContext objectContext, KeyValuePair keyValue, KeyValuePair types) { - var itemKey = keyValue.Key as string; - if (itemKey != null && (itemKey.Contains("Name") || itemKey.Contains("Test"))) + if (keyValue.Key is string itemKey && (itemKey.Contains("Name") || itemKey.Contains("Test"))) { keyValue = new KeyValuePair(itemKey + "!", keyValue.Value); } @@ -1221,13 +1220,12 @@ public void TestRemap() settings.RegisterAssembly(typeof(TestRemapObject).Assembly); var serializer = new Serializer(settings); - SerializerContext context; // Test no-remap var myCustomObjectText = serializer.Deserialize(@"!TestRemapObject Name: Test1 Enum: Value2 -", out context); +", out var context); Assert.AreEqual("Test1", myCustomObjectText.Name); Assert.AreEqual(MyRemapEnum.Value2, myCustomObjectText.Enum); Assert.IsFalse(context.HasRemapOccurred); diff --git a/src/SharpYaml.Tests/YamlNodeTrackerTest.cs b/src/SharpYaml.Tests/YamlNodeTrackerTest.cs index 7619f4b..0c1e37c 100644 --- a/src/SharpYaml.Tests/YamlNodeTrackerTest.cs +++ b/src/SharpYaml.Tests/YamlNodeTrackerTest.cs @@ -60,8 +60,8 @@ public void ValueSetTest() ScalarValueChanged valueChanged = null; tracker.TrackerEvent += (sender, args) => { - if (args is ScalarValueChanged) - valueChanged = (ScalarValueChanged)args; + if (args is ScalarValueChanged changed) + valueChanged = changed; }; ((YamlValue)stream[0].Contents).Value = "a silly scalar"; diff --git a/src/SharpYaml/Emitter.cs b/src/SharpYaml/Emitter.cs index 8606462..29a11b6 100644 --- a/src/SharpYaml/Emitter.cs +++ b/src/SharpYaml/Emitter.cs @@ -679,7 +679,7 @@ private void StateMachine(ParsingEvent evt) /// private void EmitStreamStart(ParsingEvent evt) { - if (!(evt is StreamStart)) + if (evt is not StreamStart) { throw new ArgumentException("Expected STREAM-START.", "evt"); } diff --git a/src/SharpYaml/Model/YamlNode.cs b/src/SharpYaml/Model/YamlNode.cs index 026b438..7e67e6a 100644 --- a/src/SharpYaml/Model/YamlNode.cs +++ b/src/SharpYaml/Model/YamlNode.cs @@ -65,10 +65,10 @@ public void WriteTo(IEmitter emitter, bool suppressDocumentTags = false) // Emitter will throw an exception if we attempt to use it without // starting StremStart and DocumentStart events. - if (!(events[0] is StreamStart)) + if (events[0] is not StreamStart) events.Insert(0, new StreamStart()); - if (!(events[1] is DocumentStart)) + if (events[1] is not DocumentStart) events.Insert(1, new DocumentStart()); foreach (var evnt in events) diff --git a/src/SharpYaml/Parser.cs b/src/SharpYaml/Parser.cs index 67e04b1..ee3f597 100644 --- a/src/SharpYaml/Parser.cs +++ b/src/SharpYaml/Parser.cs @@ -64,8 +64,7 @@ public static class Parser { public static IParser CreateParser(TextReader reader) { - var stringReader = reader as StringReader; - if (stringReader != null) + if (reader is StringReader stringReader) return new Parser(new StringLookAheadBuffer(stringReader.ReadToEnd())); else return new Parser(new LookAheadBuffer(reader, Scanner.MaxBufferLength)); @@ -227,8 +226,7 @@ private void Skip() /// private Event ParseStreamStart() { - StreamStart streamStart = GetCurrentToken() as StreamStart; - if (streamStart == null) + if (GetCurrentToken() is not StreamStart streamStart) { var current = GetCurrentToken(); throw new SemanticErrorException(current.Start, current.End, "Did not find expected ."); @@ -274,14 +272,14 @@ private Event ParseDocumentStart(bool isImplicit) // Parse an explicit document. - else if (!(GetCurrentToken() is StreamEnd)) + else if (GetCurrentToken() is not StreamEnd) { Mark start = GetCurrentToken().Start; TagDirectiveCollection directives = new TagDirectiveCollection(); VersionDirective versionDirective = ProcessDirectives(directives); var current = GetCurrentToken(); - if (!(current is DocumentStart)) + if (current is not DocumentStart) { throw new SemanticErrorException(current.Start, current.End, "Did not find expected ."); } @@ -320,10 +318,7 @@ private VersionDirective ProcessDirectives(TagDirectiveCollection tags) while (true) { - VersionDirective currentVersion; - TagDirective tag; - - if ((currentVersion = GetCurrentToken() as VersionDirective) != null) + if (GetCurrentToken() is VersionDirective currentVersion) { if (version != null) { @@ -337,7 +332,7 @@ private VersionDirective ProcessDirectives(TagDirectiveCollection tags) version = currentVersion; } - else if ((tag = GetCurrentToken() as TagDirective) != null) + else if (GetCurrentToken() is TagDirective tag) { if (tagDirectives.Contains(tag.Handle)) { @@ -439,8 +434,7 @@ private static Event ProcessEmptyScalar(Mark position) /// private Event ParseNode(bool isBlock, bool isIndentlessSequence) { - AnchorAlias alias = GetCurrentToken() as AnchorAlias; - if (alias != null) + if (GetCurrentToken() is AnchorAlias alias) { state = states.Pop(); Event evt = new Events.AnchorAlias(alias.Value, alias.Start, alias.End); @@ -510,8 +504,7 @@ private Event ParseNode(bool isBlock, bool isIndentlessSequence) } else { - Scalar scalar = GetCurrentToken() as Scalar; - if (scalar != null) + if (GetCurrentToken() is Scalar scalar) { bool isPlainImplicit = false; bool isQuotedImplicit = false; @@ -531,15 +524,13 @@ private Event ParseNode(bool isBlock, bool isIndentlessSequence) return evt; } - FlowSequenceStart flowSequenceStart = GetCurrentToken() as FlowSequenceStart; - if (flowSequenceStart != null) + if (GetCurrentToken() is FlowSequenceStart flowSequenceStart) { state = ParserState.YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE; return new Events.SequenceStart(anchorName, tagName, isImplicit, YamlStyle.Flow, start, flowSequenceStart.End); } - FlowMappingStart flowMappingStart = GetCurrentToken() as FlowMappingStart; - if (flowMappingStart != null) + if (GetCurrentToken() is FlowMappingStart flowMappingStart) { state = ParserState.YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE; return new Events.MappingStart(anchorName, tagName, isImplicit, YamlStyle.Flow, start, flowMappingStart.End); @@ -547,15 +538,13 @@ private Event ParseNode(bool isBlock, bool isIndentlessSequence) if (isBlock) { - BlockSequenceStart blockSequenceStart = GetCurrentToken() as BlockSequenceStart; - if (blockSequenceStart != null) + if (GetCurrentToken() is BlockSequenceStart blockSequenceStart) { state = ParserState.YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE; return new Events.SequenceStart(anchorName, tagName, isImplicit, YamlStyle.Block, start, blockSequenceStart.End); } - BlockMappingStart blockMappingStart = GetCurrentToken() as BlockMappingStart; - if (blockMappingStart != null) + if (GetCurrentToken() is BlockMappingStart blockMappingStart) { state = ParserState.YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE; return new Events.MappingStart(anchorName, tagName, isImplicit, YamlStyle.Block, start, GetCurrentToken().End); @@ -783,7 +772,7 @@ private Event ParseFlowSequenceEntry(bool isFirst) } Event evt; - if (!(GetCurrentToken() is FlowSequenceEnd)) + if (GetCurrentToken() is not FlowSequenceEnd) { if (!isFirst) { @@ -805,7 +794,7 @@ private Event ParseFlowSequenceEntry(bool isFirst) Skip(); return evt; } - else if (!(GetCurrentToken() is FlowSequenceEnd)) + else if (GetCurrentToken() is not FlowSequenceEnd) { states.Push(ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE); return ParseNode(false, false); @@ -891,7 +880,7 @@ private Event ParseFlowMappingKey(bool isFirst) Skip(); } - if (!(GetCurrentToken() is FlowMappingEnd)) + if (GetCurrentToken() is not FlowMappingEnd) { if (!isFirst) { @@ -921,7 +910,7 @@ private Event ParseFlowMappingKey(bool isFirst) return ProcessEmptyScalar(GetCurrentToken().Start); } } - else if (!(GetCurrentToken() is FlowMappingEnd)) + else if (GetCurrentToken() is not FlowMappingEnd) { states.Push(ParserState.YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE); return ParseNode(false, false); diff --git a/src/SharpYaml/Schemas/SchemaBase.cs b/src/SharpYaml/Schemas/SchemaBase.cs index 1ff7787..6b25d1c 100644 --- a/src/SharpYaml/Schemas/SchemaBase.cs +++ b/src/SharpYaml/Schemas/SchemaBase.cs @@ -110,20 +110,17 @@ public string GetDefaultTag(NodeEvent nodeEvent) if (nodeEvent == null) throw new ArgumentNullException("nodeEvent"); - var mapping = nodeEvent as MappingStart; - if (mapping != null) + if (nodeEvent is MappingStart mapping) { return GetDefaultTag(mapping); } - var sequence = nodeEvent as SequenceStart; - if (sequence != null) + if (nodeEvent is SequenceStart sequence) { return GetDefaultTag(sequence); } - var scalar = nodeEvent as Scalar; - if (scalar != null) + if (nodeEvent is Scalar scalar) { TryParse(scalar, false, out string tag, out object value); return tag; diff --git a/src/SharpYaml/Serialization/Descriptors/DefaultKeyComparer.cs b/src/SharpYaml/Serialization/Descriptors/DefaultKeyComparer.cs index 5a4df71..d539b99 100644 --- a/src/SharpYaml/Serialization/Descriptors/DefaultKeyComparer.cs +++ b/src/SharpYaml/Serialization/Descriptors/DefaultKeyComparer.cs @@ -40,9 +40,7 @@ public class DefaultKeyComparer : IComparer { public virtual int Compare(object x, object y) { - var left = x as IMemberDescriptor; - var right = y as IMemberDescriptor; - if (left != null && right != null) + if (x is IMemberDescriptor left && y is IMemberDescriptor right) { // If order is defined, first order by order if (left.Order.HasValue | right.Order.HasValue) @@ -61,14 +59,12 @@ public virtual int Compare(object x, object y) return string.CompareOrdinal((string)x, (string)y); } - var leftComparable = x as IComparable; - if (leftComparable != null) + if (x is IComparable leftComparable) { return leftComparable.CompareTo(y); } - var rightComparable = y as IComparable; - return rightComparable != null ? rightComparable.CompareTo(y) : 0; + return y is IComparable rightComparable ? rightComparable.CompareTo(y) : 0; } } } diff --git a/src/SharpYaml/Serialization/Descriptors/DictionaryDescriptor.cs b/src/SharpYaml/Serialization/Descriptors/DictionaryDescriptor.cs index d17730a..e09c71c 100644 --- a/src/SharpYaml/Serialization/Descriptors/DictionaryDescriptor.cs +++ b/src/SharpYaml/Serialization/Descriptors/DictionaryDescriptor.cs @@ -163,12 +163,14 @@ public IEnumerable> GetEnumerator(object dictionary var simpleDictionary = (IDictionary)dictionary; foreach (var keyValueObject in simpleDictionary) { - if (!(keyValueObject is DictionaryEntry)) + if (keyValueObject is not DictionaryEntry entry) { throw new NotSupportedException($"Key value-pair type [{keyValueObject}] is not supported for IDictionary. Only DictionaryEntry"); } - var entry = (DictionaryEntry)keyValueObject; - yield return new KeyValuePair(entry.Key, entry.Value); + else + { + yield return new KeyValuePair(entry.Key, entry.Value); + } } } } @@ -184,8 +186,7 @@ public void AddToDictionary(object dictionary, object key, object value) { if (dictionary == null) throw new ArgumentNullException("dictionary"); - var simpleDictionary = dictionary as IDictionary; - if (simpleDictionary != null) + if (dictionary is IDictionary simpleDictionary) { simpleDictionary.Add(key, value); } diff --git a/src/SharpYaml/Serialization/Descriptors/ObjectDescriptor.cs b/src/SharpYaml/Serialization/Descriptors/ObjectDescriptor.cs index e624403..a03bc16 100644 --- a/src/SharpYaml/Serialization/Descriptors/ObjectDescriptor.cs +++ b/src/SharpYaml/Serialization/Descriptors/ObjectDescriptor.cs @@ -104,8 +104,7 @@ public ObjectDescriptor(IAttributeRegistry attributeRegistry, Type type, bool em this.style = YamlStyle.Any; foreach (var attribute in attributes) { - var styleAttribute = attribute as YamlStyleAttribute; - if (styleAttribute != null) + if (attribute is YamlStyleAttribute styleAttribute) { style = styleAttribute.Style; continue; @@ -285,26 +284,25 @@ protected virtual bool PrepareMember(MemberDescriptorBase member) return false; } - if (attribute is YamlMemberAttribute) + if (attribute is YamlMemberAttribute yamlMemberAttribute) { - memberAttribute = (YamlMemberAttribute)attribute; + memberAttribute = yamlMemberAttribute; continue; } - if (attribute is DefaultValueAttribute) + if (attribute is DefaultValueAttribute defaultValueAttribute1) { - defaultValueAttribute = (DefaultValueAttribute)attribute; + defaultValueAttribute = defaultValueAttribute1; continue; } - if (attribute is YamlStyleAttribute) + if (attribute is YamlStyleAttribute yamlStyleAttribute) { - styleAttribute = (YamlStyleAttribute)attribute; + styleAttribute = yamlStyleAttribute; continue; } - var yamlRemap = attribute as YamlRemapAttribute; - if (yamlRemap != null) + if (attribute is YamlRemapAttribute yamlRemap) { if (member.AlternativeNames == null) { diff --git a/src/SharpYaml/Serialization/Descriptors/PrimitiveDescriptor.cs b/src/SharpYaml/Serialization/Descriptors/PrimitiveDescriptor.cs index 21f0772..af8143a 100644 --- a/src/SharpYaml/Serialization/Descriptors/PrimitiveDescriptor.cs +++ b/src/SharpYaml/Serialization/Descriptors/PrimitiveDescriptor.cs @@ -79,8 +79,7 @@ public PrimitiveDescriptor(IAttributeRegistry attributeRegistry, Type type, IMem var attributes = attributeRegistry.GetAttributes(member); foreach (var attribute in attributes) { - var yamlRemap = attribute as YamlRemapAttribute; - if (yamlRemap != null) + if (attribute is YamlRemapAttribute yamlRemap) { if (enumRemap == null) { diff --git a/src/SharpYaml/Serialization/Descriptors/TypeDescriptorFactory.cs b/src/SharpYaml/Serialization/Descriptors/TypeDescriptorFactory.cs index f8c171a..7cf3b0a 100644 --- a/src/SharpYaml/Serialization/Descriptors/TypeDescriptorFactory.cs +++ b/src/SharpYaml/Serialization/Descriptors/TypeDescriptorFactory.cs @@ -94,8 +94,7 @@ public ITypeDescriptor Find(Type type, IComparer memberComparer) descriptor = Create(type); - var objectDescriptor = descriptor as ObjectDescriptor; - if (objectDescriptor != null) + if (descriptor is ObjectDescriptor objectDescriptor) { objectDescriptor.SortMembers(memberComparer); } diff --git a/src/SharpYaml/Serialization/Serializer.cs b/src/SharpYaml/Serialization/Serializer.cs index ba2dcac..59e5d8d 100644 --- a/src/SharpYaml/Serialization/Serializer.cs +++ b/src/SharpYaml/Serialization/Serializer.cs @@ -212,8 +212,7 @@ public void Serialize(IEmitter emitter, object graph, Type type, SerializerConte // Configure the emitter // TODO the current emitter is not enough configurable to format its output // This should be improved - var defaultEmitter = emitter as Emitter; - if (defaultEmitter != null) + if (emitter is Emitter defaultEmitter) { defaultEmitter.ForceIndentLess = settings.IndentLess; } diff --git a/src/SharpYaml/Serialization/Serializers/DefaultObjectSerializerBackend.cs b/src/SharpYaml/Serialization/Serializers/DefaultObjectSerializerBackend.cs index aca66cf..f76ba01 100644 --- a/src/SharpYaml/Serialization/Serializers/DefaultObjectSerializerBackend.cs +++ b/src/SharpYaml/Serialization/Serializers/DefaultObjectSerializerBackend.cs @@ -51,17 +51,15 @@ public virtual YamlStyle GetStyle(ref ObjectContext objectContext) if (style == YamlStyle.Any) { bool isPrimitiveElementType = false; - var collectionDescriptor = objectContext.Descriptor as CollectionDescriptor; int count = 0; - if (collectionDescriptor != null) + if (objectContext.Descriptor is CollectionDescriptor collectionDescriptor) { isPrimitiveElementType = PrimitiveDescriptor.IsPrimitive(collectionDescriptor.ElementType); count = collectionDescriptor.GetCollectionCount(objectContext.Instance); } else { - var arrayDescriptor = objectContext.Descriptor as ArrayDescriptor; - if (arrayDescriptor != null) + if (objectContext.Descriptor is ArrayDescriptor arrayDescriptor) { isPrimitiveElementType = PrimitiveDescriptor.IsPrimitive(arrayDescriptor.ElementType); count = objectContext.Instance != null ? ((Array)objectContext.Instance).Length : -1; diff --git a/src/SharpYaml/Serialization/Serializers/TagTypeSerializer.cs b/src/SharpYaml/Serialization/Serializers/TagTypeSerializer.cs index 3efad56..aa00ce0 100644 --- a/src/SharpYaml/Serialization/Serializers/TagTypeSerializer.cs +++ b/src/SharpYaml/Serialization/Serializers/TagTypeSerializer.cs @@ -66,8 +66,7 @@ public override object ReadYaml(ref ObjectContext objectContext) throw new YamlException("Unable to parse input"); } - var node = parsingEvent as NodeEvent; - if (node == null) + if (parsingEvent is not NodeEvent node) { throw new YamlException(parsingEvent.Start, parsingEvent.End, $"Unexpected parsing event found [{parsingEvent}]. Expecting Scalar, Mapping or Sequence"); } @@ -102,7 +101,7 @@ public override object ReadYaml(ref ObjectContext objectContext) object value = objectContext.Instance; // Handle explicit null scalar - if (node is Scalar && objectContext.SerializerContext.Schema.TryParse((Scalar)node, typeof(object), out value)) + if (node is Scalar scalar && objectContext.SerializerContext.Schema.TryParse(scalar, typeof(object), out value)) { // The value was pick up, go to next objectContext.Reader.Parser.MoveNext(); @@ -148,9 +147,9 @@ public override object ReadYaml(ref ObjectContext objectContext) objectContext.Descriptor = objectContext.SerializerContext.FindTypeDescriptor(type); // If this is a nullable descriptor, use its underlying type directly - if (objectContext.Descriptor is NullableDescriptor) + if (objectContext.Descriptor is NullableDescriptor descriptor) { - objectContext.Descriptor = objectContext.SerializerContext.FindTypeDescriptor(((NullableDescriptor)objectContext.Descriptor).UnderlyingType); + objectContext.Descriptor = objectContext.SerializerContext.FindTypeDescriptor(descriptor.UnderlyingType); } return base.ReadYaml(ref objectContext); } @@ -170,9 +169,9 @@ public override void WriteYaml(ref ObjectContext objectContext) // If we have a nullable value, get its type directly and replace the descriptor - if (objectContext.Descriptor is NullableDescriptor) + if (objectContext.Descriptor is NullableDescriptor descriptor) { - objectContext.Descriptor = objectContext.SerializerContext.FindTypeDescriptor(((NullableDescriptor)objectContext.Descriptor).UnderlyingType); + objectContext.Descriptor = objectContext.SerializerContext.FindTypeDescriptor(descriptor.UnderlyingType); } // Expected type diff --git a/src/SharpYaml/Serialization/YamlAliasNode.cs b/src/SharpYaml/Serialization/YamlAliasNode.cs index 1f8abf8..962c764 100644 --- a/src/SharpYaml/Serialization/YamlAliasNode.cs +++ b/src/SharpYaml/Serialization/YamlAliasNode.cs @@ -96,8 +96,7 @@ public override void Accept(IYamlVisitor visitor) /// public override bool Equals(object other) { - var obj = other as YamlAliasNode; - return obj != null && Equals(obj) && SafeEquals(Anchor, obj.Anchor); + return other is YamlAliasNode obj && Equals(obj) && SafeEquals(Anchor, obj.Anchor); } /// diff --git a/src/SharpYaml/Serialization/YamlMappingNode.cs b/src/SharpYaml/Serialization/YamlMappingNode.cs index 9e03fc5..dc884fc 100644 --- a/src/SharpYaml/Serialization/YamlMappingNode.cs +++ b/src/SharpYaml/Serialization/YamlMappingNode.cs @@ -294,8 +294,7 @@ public override void Accept(IYamlVisitor visitor) /// public override bool Equals(object other) { - var obj = other as YamlMappingNode; - if (obj == null || !Equals(obj) || children.Count != obj.children.Count) + if (other is not YamlMappingNode obj || !Equals(obj) || children.Count != obj.children.Count) { return false; } diff --git a/src/SharpYaml/Serialization/YamlScalarNode.cs b/src/SharpYaml/Serialization/YamlScalarNode.cs index 3289198..ff1ed82 100644 --- a/src/SharpYaml/Serialization/YamlScalarNode.cs +++ b/src/SharpYaml/Serialization/YamlScalarNode.cs @@ -131,8 +131,7 @@ public override void Accept(IYamlVisitor visitor) /// public override bool Equals(object other) { - var obj = other as YamlScalarNode; - return obj != null && Equals(obj) && SafeEquals(Value, obj.Value); + return other is YamlScalarNode obj && Equals(obj) && SafeEquals(Value, obj.Value); } /// diff --git a/src/SharpYaml/Serialization/YamlSequenceNode.cs b/src/SharpYaml/Serialization/YamlSequenceNode.cs index ad7c77d..914c2e4 100644 --- a/src/SharpYaml/Serialization/YamlSequenceNode.cs +++ b/src/SharpYaml/Serialization/YamlSequenceNode.cs @@ -200,8 +200,7 @@ public override void Accept(IYamlVisitor visitor) /// public override bool Equals(object other) { - var obj = other as YamlSequenceNode; - if (obj == null || !Equals(obj) || children.Count != obj.children.Count) + if (other is not YamlSequenceNode obj || !Equals(obj) || children.Count != obj.children.Count) { return false; } diff --git a/src/SharpYaml/SharpYaml.csproj b/src/SharpYaml/SharpYaml.csproj index 406ebf9..9ca781b 100644 --- a/src/SharpYaml/SharpYaml.csproj +++ b/src/SharpYaml/SharpYaml.csproj @@ -16,7 +16,8 @@ true true - snupkg + snupkg + 10 diff --git a/src/SharpYaml/Tokens/TagDirective.cs b/src/SharpYaml/Tokens/TagDirective.cs index e87fdf4..e0977cc 100644 --- a/src/SharpYaml/Tokens/TagDirective.cs +++ b/src/SharpYaml/Tokens/TagDirective.cs @@ -120,8 +120,7 @@ public TagDirective(string handle, string prefix, Mark start, Mark end) /// public override bool Equals(object obj) { - TagDirective other = obj as TagDirective; - return other != null && handle.Equals(other.handle) && prefix.Equals(other.prefix); + return obj is TagDirective other && handle.Equals(other.handle) && prefix.Equals(other.prefix); } /// diff --git a/src/SharpYaml/Tokens/VersionDirective.cs b/src/SharpYaml/Tokens/VersionDirective.cs index 4e25062..8dd2ece 100644 --- a/src/SharpYaml/Tokens/VersionDirective.cs +++ b/src/SharpYaml/Tokens/VersionDirective.cs @@ -90,8 +90,7 @@ public VersionDirective(Version version, Mark start, Mark end) /// public override bool Equals(object obj) { - VersionDirective other = obj as VersionDirective; - return other != null && version.Equals(other.version); + return obj is VersionDirective other && version.Equals(other.version); } /// diff --git a/src/SharpYaml/Version.cs b/src/SharpYaml/Version.cs index 5f1f477..1dfad5e 100644 --- a/src/SharpYaml/Version.cs +++ b/src/SharpYaml/Version.cs @@ -86,8 +86,7 @@ public Version(int major, int minor) /// public override bool Equals(object obj) { - Version other = obj as Version; - return other != null && major == other.major && minor == other.minor; + return obj is Version other && major == other.major && minor == other.minor; } ///