Skip to content

Commit

Permalink
bump: support .net6
Browse files Browse the repository at this point in the history
  • Loading branch information
riemannulus committed Aug 1, 2024
1 parent 2335204 commit 9213082
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Bencodex/Bencodex.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<NoWarn>CS1591</NoWarn>
<IsTestProject>false</IsTestProject>
<DebugType>portable</DebugType>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0</TargetFrameworks>
<CodeAnalysisRuleSet>../Bencodex.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Bencodex/Misc/KeyComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private KeyComparer()
}

/// <inheritdoc cref="IComparer{T}.Compare(T, T)"/>
public int Compare(IKey x, IKey y)
public int Compare(IKey? x, IKey? y)
{
if (x is Binary xb && y is Binary yb)
{
Expand All @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion Bencodex/Types/Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions Bencodex/Types/Boolean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
10 changes: 5 additions & 5 deletions Bencodex/Types/Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ public IEnumerator<KeyValuePair<IKey, IValue>> GetEnumerator()
/// <inheritdoc cref="IReadOnlyDictionary{TKey,TValue}.TryGetValue(TKey, out TValue)"/>
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;
Expand Down Expand Up @@ -1629,13 +1629,13 @@ IEnumerable<KeyValuePair<IKey, IValue>> 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<IKey, IValue> kv in _dict)
{
Expand Down
4 changes: 2 additions & 2 deletions Bencodex/Types/Integer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
18 changes: 9 additions & 9 deletions Bencodex/Types/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ public long EncodingLength
/// <inheritdoc cref="IReadOnlyList{T}.this[int]"/>
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++)
{
Expand Down Expand Up @@ -389,7 +389,7 @@ int IImmutableList<IValue>.IndexOf(
IValue item,
int index,
int count,
IEqualityComparer<IValue> equalityComparer
IEqualityComparer<IValue>? equalityComparer
) =>
_values.IndexOf(
item,
Expand All @@ -414,7 +414,7 @@ int IImmutableList<IValue>.LastIndexOf(
IValue item,
int index,
int count,
IEqualityComparer<IValue> equalityComparer
IEqualityComparer<IValue>? equalityComparer
) =>
_values.LastIndexOf(
item,
Expand All @@ -425,7 +425,7 @@ IEqualityComparer<IValue> equalityComparer
[Obsolete("This operation immediately loads all unloaded values on the memory.")]
IImmutableList<IValue> IImmutableList<IValue>.Remove(
IValue value,
IEqualityComparer<IValue> equalityComparer
IEqualityComparer<IValue>? equalityComparer
) =>
new List(_values.Remove(value, equalityComparer));

Expand All @@ -441,7 +441,7 @@ IImmutableList<IValue> IImmutableList<IValue>.RemoveAt(int index) =>
[Obsolete("This operation immediately loads all unloaded values on the memory.")]
IImmutableList<IValue> IImmutableList<IValue>.RemoveRange(
IEnumerable<IValue> items,
IEqualityComparer<IValue> equalityComparer
IEqualityComparer<IValue>? equalityComparer
) =>
new List(_values.RemoveRange(items.Select(v => v), equalityComparer));

Expand All @@ -452,7 +452,7 @@ IImmutableList<IValue> IImmutableList<IValue>.RemoveRange(int index, int count)
IImmutableList<IValue> IImmutableList<IValue>.Replace(
IValue oldValue,
IValue newValue,
IEqualityComparer<IValue> equalityComparer
IEqualityComparer<IValue>? equalityComparer
) =>
new List(
_values.Replace(
Expand Down
6 changes: 3 additions & 3 deletions Bencodex/Types/Null.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Null>.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<IValue>.Equals(IValue other) =>
bool IEquatable<IValue>.Equals(IValue? other) =>
other is Null;

bool IEquatable<Null>.Equals(Null other) => true;
Expand Down
4 changes: 2 additions & 2 deletions Bencodex/Types/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 9213082

Please sign in to comment.