From 9213082a1379aeb349f2fc2fb57d6ed34a95cd79 Mon Sep 17 00:00:00 2001 From: Suho Lee Date: Thu, 1 Aug 2024 14:19:57 +0900 Subject: [PATCH] bump: support .net6 --- Bencodex/Bencodex.csproj | 2 +- Bencodex/Misc/KeyComparer.cs | 4 ++-- Bencodex/Types/Binary.cs | 2 +- Bencodex/Types/Boolean.cs | 4 ++-- Bencodex/Types/Dictionary.cs | 10 +++++----- Bencodex/Types/Integer.cs | 4 ++-- Bencodex/Types/List.cs | 18 +++++++++--------- Bencodex/Types/Null.cs | 6 +++--- Bencodex/Types/Text.cs | 4 ++-- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Bencodex/Bencodex.csproj b/Bencodex/Bencodex.csproj index f0c90a6..32385f5 100644 --- a/Bencodex/Bencodex.csproj +++ b/Bencodex/Bencodex.csproj @@ -24,7 +24,7 @@ CS1591 false portable - netstandard2.0;netstandard2.1 + netstandard2.0;netstandard2.1;net6.0 ../Bencodex.ruleset diff --git a/Bencodex/Misc/KeyComparer.cs b/Bencodex/Misc/KeyComparer.cs index b7c3504..3d20b37 100644 --- a/Bencodex/Misc/KeyComparer.cs +++ b/Bencodex/Misc/KeyComparer.cs @@ -19,7 +19,7 @@ private KeyComparer() } /// - public int Compare(IKey x, IKey y) + public int Compare(IKey? x, IKey? y) { if (x is Binary xb && y is Binary yb) { @@ -30,7 +30,7 @@ public int Compare(IKey x, IKey y) return xt.CompareTo(yt); } - return (x.Kind == ValueKind.Text).CompareTo(y.Kind == ValueKind.Text); + return (x?.Kind == ValueKind.Text).CompareTo(y?.Kind == ValueKind.Text); } } } diff --git a/Bencodex/Types/Binary.cs b/Bencodex/Types/Binary.cs index 6c4038c..ea7b274 100644 --- a/Bencodex/Types/Binary.cs +++ b/Bencodex/Types/Binary.cs @@ -193,7 +193,7 @@ public static Binary FromBase64(string base64) public override bool Equals(object? obj) => obj is Binary other && Equals(other); - public bool Equals(IValue other) => other is Binary i && Equals(i); + public bool Equals(IValue? other) => other is Binary i && Equals(i); public bool Equals(Binary other) => ByteArray.SequenceEqual(other.ByteArray); diff --git a/Bencodex/Types/Boolean.cs b/Bencodex/Types/Boolean.cs index d0eb54d..8798f50 100644 --- a/Bencodex/Types/Boolean.cs +++ b/Bencodex/Types/Boolean.cs @@ -70,9 +70,9 @@ public int CompareTo(object? obj) public bool Equals(Boolean other) => Value == other.Value; - public bool Equals(IValue other) => other is Boolean b && Equals(b); + public bool Equals(IValue? other) => other is Boolean b && Equals(b); - public override bool Equals(object obj) => obj is Boolean b && Equals(b); + public override bool Equals(object? obj) => obj is Boolean b && Equals(b); public override int GetHashCode() { diff --git a/Bencodex/Types/Dictionary.cs b/Bencodex/Types/Dictionary.cs index f70b3bd..190cc46 100644 --- a/Bencodex/Types/Dictionary.cs +++ b/Bencodex/Types/Dictionary.cs @@ -1039,7 +1039,7 @@ public IEnumerator> GetEnumerator() /// public bool TryGetValue(IKey key, out IValue value) { - if (_dict.TryGetValue(key, out IValue v)) + if (_dict.TryGetValue(key, out IValue? v)) { value = v; return true; @@ -1629,13 +1629,13 @@ IEnumerable> items public bool TryGetKey(IKey equalKey, out IKey actualKey) => _dict.TryGetKey(equalKey, out actualKey); - public override bool Equals(object obj) => obj is Dictionary d && Equals(d); + public override bool Equals(object? obj) => obj is Dictionary d && Equals(d); - public bool Equals(IValue other) => other is Dictionary d && Equals(d); + public bool Equals(IValue? other) => other is Dictionary d && Equals(d); - public bool Equals(Dictionary other) + public bool Equals(Dictionary? other) { - if (Count == other.Count) + if (Count == other?.Count) { foreach (KeyValuePair kv in _dict) { diff --git a/Bencodex/Types/Integer.cs b/Bencodex/Types/Integer.cs index 3f7d13e..0214fa7 100644 --- a/Bencodex/Types/Integer.cs +++ b/Bencodex/Types/Integer.cs @@ -212,9 +212,9 @@ public int CompareTo(Integer other) return Value.CompareTo(other.Value); } - public override bool Equals(object obj) => obj is Integer other && Equals(other); + public override bool Equals(object? obj) => obj is Integer other && Equals(other); - public bool Equals(IValue other) => other is Integer i && Equals(i); + public bool Equals(IValue? other) => other is Integer i && Equals(i); public bool Equals(Integer other) => Value.Equals(other.Value); diff --git a/Bencodex/Types/List.cs b/Bencodex/Types/List.cs index 7c6814d..74fe48b 100644 --- a/Bencodex/Types/List.cs +++ b/Bencodex/Types/List.cs @@ -208,13 +208,13 @@ public long EncodingLength /// public IValue this[int index] => _values[index]; - public override bool Equals(object obj) => obj is List l && Equals(l); + public override bool Equals(object? obj) => obj is List l && Equals(l); - public bool Equals(IValue other) => other is List l && Equals(l); + public bool Equals(IValue? other) => other is List l && Equals(l); - public bool Equals(List other) + public bool Equals(List? other) { - if (Count == other.Count) + if (Count == other?.Count) { for (int i = 0; i < Count; i++) { @@ -389,7 +389,7 @@ int IImmutableList.IndexOf( IValue item, int index, int count, - IEqualityComparer equalityComparer + IEqualityComparer? equalityComparer ) => _values.IndexOf( item, @@ -414,7 +414,7 @@ int IImmutableList.LastIndexOf( IValue item, int index, int count, - IEqualityComparer equalityComparer + IEqualityComparer? equalityComparer ) => _values.LastIndexOf( item, @@ -425,7 +425,7 @@ IEqualityComparer equalityComparer [Obsolete("This operation immediately loads all unloaded values on the memory.")] IImmutableList IImmutableList.Remove( IValue value, - IEqualityComparer equalityComparer + IEqualityComparer? equalityComparer ) => new List(_values.Remove(value, equalityComparer)); @@ -441,7 +441,7 @@ IImmutableList IImmutableList.RemoveAt(int index) => [Obsolete("This operation immediately loads all unloaded values on the memory.")] IImmutableList IImmutableList.RemoveRange( IEnumerable items, - IEqualityComparer equalityComparer + IEqualityComparer? equalityComparer ) => new List(_values.RemoveRange(items.Select(v => v), equalityComparer)); @@ -452,7 +452,7 @@ IImmutableList IImmutableList.RemoveRange(int index, int count) IImmutableList IImmutableList.Replace( IValue oldValue, IValue newValue, - IEqualityComparer equalityComparer + IEqualityComparer? equalityComparer ) => new List( _values.Replace( diff --git a/Bencodex/Types/Null.cs b/Bencodex/Types/Null.cs index 4643e45..73b73d1 100644 --- a/Bencodex/Types/Null.cs +++ b/Bencodex/Types/Null.cs @@ -29,16 +29,16 @@ namespace Bencodex.Types public override int GetHashCode() => 0; - int IComparable.CompareTo(object obj) => obj is Null ? 0 : -1; + int IComparable.CompareTo(object? obj) => obj is Null ? 0 : -1; int IComparable.CompareTo(Null other) => 0; - public override bool Equals(object obj) + public override bool Equals(object? obj) { return ReferenceEquals(null, obj) || obj is Null; } - bool IEquatable.Equals(IValue other) => + bool IEquatable.Equals(IValue? other) => other is Null; bool IEquatable.Equals(Null other) => true; diff --git a/Bencodex/Types/Text.cs b/Bencodex/Types/Text.cs index 2a12df4..093e7fd 100644 --- a/Bencodex/Types/Text.cs +++ b/Bencodex/Types/Text.cs @@ -64,11 +64,11 @@ public static implicit operator Text(string s) public static bool operator !=(string left, Text right) => !left.Equals(right.Value); - public bool Equals(IValue other) => other is Text t && Equals(t); + public bool Equals(IValue? other) => other is Text t && Equals(t); public bool Equals(Text other) => Value.Equals(other); - public override bool Equals(object obj) => obj is Text t && Equals(t); + public override bool Equals(object? obj) => obj is Text t && Equals(t); public override int GetHashCode() {