Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide ToDictionary() in net8+ #1040

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions MoreLinq.Test/ToDictionaryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void ToDictionaryWithKeyValuePairs()
KeyValuePair.Create("baz", 789),
};

var dict = pairs.ToDictionary();
var dict = MoreEnumerable.ToDictionary(pairs);

Assert.That(dict["foo"], Is.EqualTo(123));
Assert.That(dict["bar"], Is.EqualTo(456));
Expand All @@ -50,7 +50,7 @@ public void ToDictionaryWithCouples()
("baz", 789),
};

var dict = pairs.ToDictionary();
var dict = MoreEnumerable.ToDictionary(pairs);

Assert.That(dict["foo"], Is.EqualTo(123));
Assert.That(dict["bar"], Is.EqualTo(456));
Expand All @@ -67,7 +67,7 @@ public void ToDictionaryWithKeyValuePairsWithComparer()
KeyValuePair.Create("baz", 789),
};

var dict = pairs.ToDictionary(StringComparer.OrdinalIgnoreCase);
var dict = MoreEnumerable.ToDictionary(pairs, StringComparer.OrdinalIgnoreCase);

Assert.That(dict["FOO"], Is.EqualTo(123));
Assert.That(dict["BAR"], Is.EqualTo(456));
Expand All @@ -84,7 +84,7 @@ public void ToDictionaryWithCouplesWithComparer()
("baz", 789),
};

var dict = pairs.ToDictionary(StringComparer.OrdinalIgnoreCase);
var dict = MoreEnumerable.ToDictionary(pairs, StringComparer.OrdinalIgnoreCase);

Assert.That(dict["FOO"], Is.EqualTo(123));
Assert.That(dict["BAR"], Is.EqualTo(456));
Expand Down
24 changes: 24 additions & 0 deletions MoreLinq/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:MoreLinq.MoreEnumerable.ToDictionary``2(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{``0,``1}},System.Collections.Generic.IEqualityComparer{``0})</Target>
<Left>lib/net6.0/MoreLinq.dll</Left>
<Right>lib/net8.0/MoreLinq.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:MoreLinq.MoreEnumerable.ToDictionary``2(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{``0,``1}})</Target>
<Left>lib/net6.0/MoreLinq.dll</Left>
<Right>lib/net8.0/MoreLinq.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:MoreLinq.MoreEnumerable.ToDictionary``2(System.Collections.Generic.IEnumerable{System.ValueTuple{``0,``1}},System.Collections.Generic.IEqualityComparer{``0})</Target>
<Left>lib/net6.0/MoreLinq.dll</Left>
<Right>lib/net8.0/MoreLinq.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:MoreLinq.MoreEnumerable.ToDictionary``2(System.Collections.Generic.IEnumerable{System.ValueTuple{``0,``1}})</Target>
<Left>lib/net6.0/MoreLinq.dll</Left>
<Right>lib/net8.0/MoreLinq.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:MoreLinq.SequenceException.#ctor(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext)</Target>
Expand Down
8 changes: 4 additions & 4 deletions MoreLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -656,10 +656,10 @@ static MoreLinq.MoreEnumerable.ToDelimitedString(this System.Collections.Generic
static MoreLinq.MoreEnumerable.ToDelimitedString(this System.Collections.Generic.IEnumerable<ulong>! source, string! delimiter) -> string!
static MoreLinq.MoreEnumerable.ToDelimitedString(this System.Collections.Generic.IEnumerable<ushort>! source, string! delimiter) -> string!
static MoreLinq.MoreEnumerable.ToDelimitedString<TSource>(this System.Collections.Generic.IEnumerable<TSource>! source, string! delimiter) -> string!
static MoreLinq.MoreEnumerable.ToDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<(TKey Key, TValue Value)>! source) -> System.Collections.Generic.Dictionary<TKey, TValue>!
static MoreLinq.MoreEnumerable.ToDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<(TKey Key, TValue Value)>! source, System.Collections.Generic.IEqualityComparer<TKey>? comparer) -> System.Collections.Generic.Dictionary<TKey, TValue>!
static MoreLinq.MoreEnumerable.ToDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>! source) -> System.Collections.Generic.Dictionary<TKey, TValue>!
static MoreLinq.MoreEnumerable.ToDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>! source, System.Collections.Generic.IEqualityComparer<TKey>? comparer) -> System.Collections.Generic.Dictionary<TKey, TValue>!
static MoreLinq.MoreEnumerable.ToDictionary<TKey, TValue>(System.Collections.Generic.IEnumerable<(TKey Key, TValue Value)>! source) -> System.Collections.Generic.Dictionary<TKey, TValue>!
static MoreLinq.MoreEnumerable.ToDictionary<TKey, TValue>(System.Collections.Generic.IEnumerable<(TKey Key, TValue Value)>! source, System.Collections.Generic.IEqualityComparer<TKey>? comparer) -> System.Collections.Generic.Dictionary<TKey, TValue>!
static MoreLinq.MoreEnumerable.ToDictionary<TKey, TValue>(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>! source) -> System.Collections.Generic.Dictionary<TKey, TValue>!
static MoreLinq.MoreEnumerable.ToDictionary<TKey, TValue>(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>! source, System.Collections.Generic.IEqualityComparer<TKey>? comparer) -> System.Collections.Generic.Dictionary<TKey, TValue>!
static MoreLinq.MoreEnumerable.ToHashSet<TSource>(System.Collections.Generic.IEnumerable<TSource>! source) -> System.Collections.Generic.HashSet<TSource>!
static MoreLinq.MoreEnumerable.ToHashSet<TSource>(System.Collections.Generic.IEnumerable<TSource>! source, System.Collections.Generic.IEqualityComparer<TSource>? comparer) -> System.Collections.Generic.HashSet<TSource>!
static MoreLinq.MoreEnumerable.ToLookup<TKey, TValue>(this System.Collections.Generic.IEnumerable<(TKey Key, TValue Value)>! source) -> System.Linq.ILookup<TKey, TValue>!
Expand Down
26 changes: 24 additions & 2 deletions MoreLinq/ToDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ static partial class MoreEnumerable
/// mapped to their keys.
/// </returns>

#if !NET8_0_OR_GREATER
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source)
where TKey : notnull =>
source.ToDictionary(null);
#else
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> source)
where TKey : notnull =>
#endif
ToDictionary(source, null);

/// <summary>
/// Creates a <see cref="Dictionary{TKey,TValue}" /> from a sequence of
Expand All @@ -53,9 +58,15 @@ public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerab
/// mapped to their keys.
/// </returns>

#if !NET8_0_OR_GREATER
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source,
IEqualityComparer<TKey>? comparer)
where TKey : notnull
#else
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> source,
IEqualityComparer<TKey>? comparer)
where TKey : notnull
#endif
{
if (source == null) throw new ArgumentNullException(nameof(source));
return source.ToDictionary(e => e.Key, e => e.Value, comparer);
Expand All @@ -74,9 +85,14 @@ public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerab
/// mapped to their keys.
/// </returns>

#if !NET8_0_OR_GREATER
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<(TKey Key, TValue Value)> source)
where TKey : notnull =>
source.ToDictionary(null);
#else
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(IEnumerable<(TKey Key, TValue Value)> source)
where TKey : notnull =>
#endif
ToDictionary(source, null);

/// <summary>
/// Creates a <see cref="Dictionary{TKey,TValue}" /> from a sequence of
Expand All @@ -92,9 +108,15 @@ public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerab
/// mapped to their keys.
/// </returns>

#if !NET8_0_OR_GREATER
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<(TKey Key, TValue Value)> source,
IEqualityComparer<TKey>? comparer)
where TKey : notnull
#else
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(IEnumerable<(TKey Key, TValue Value)> source,
IEqualityComparer<TKey>? comparer)
where TKey : notnull
#endif
{
if (source == null) throw new ArgumentNullException(nameof(source));
return source.ToDictionary(e => e.Key, e => e.Value, comparer);
Expand Down