Skip to content

Commit

Permalink
Merge pull request #23 from thomaslevesque/remove-compat-methods
Browse files Browse the repository at this point in the history
Remove compat methods
  • Loading branch information
thomaslevesque authored Jun 23, 2021
2 parents f85700f + 4a148b7 commit 6d4f81a
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 4,302 deletions.
4,097 changes: 0 additions & 4,097 deletions Linq.Extras.ndproj

This file was deleted.

3 changes: 0 additions & 3 deletions Linq.Extras.sln
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,4 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1AC5F1E6-BC9A-4EB9-BFD3-7F548BC6F652}
EndGlobalSection
GlobalSection(NDepend) = preSolution
Project = ".\Linq.Extras.ndproj"
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

A set of extension and helper methods to complement the ones from `System.Linq.Enumerable`.

Some of these methods are just shortcuts for common Linq operations (e.g. `Append`, `IsNullOrEmpty`), or improvements to
Some of these methods are just shortcuts for common Linq operations (e.g. `IsNullOrEmpty`), or improvements to
existing Linq methods (e.g. specify default value for `FirstOrDefault`, specify comparer for `Max`). Others do more
complex things that have no equivalent in standard Linq (`RankBy`, `DistinctUntilChanged`).

Expand Down
52 changes: 0 additions & 52 deletions src/Linq.Extras/AppendPrepend.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Linq.Extras/Flatten.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static IEnumerable<TResult> DepthFirstFlattenIterator<TNode, TResult>(th
var list = source.Select(n => new NodeWithLevel<TNode>(n, 0)).ToLinkedList();
while (list.Count > 0)
{
var current = list.First.Value;
var current = list.First!.Value;
list.RemoveFirst();
yield return resultSelector(current.Node, current.Level);
var llNode = list.First;
Expand Down
10 changes: 0 additions & 10 deletions src/Linq.Extras/Internal/ExcludeFromCodeCoverageAttribute.cs

This file was deleted.

33 changes: 7 additions & 26 deletions src/Linq.Extras/Linq.Extras.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.0;netstandard1.6;netstandard2.0;netstandard2.1;net45;net471;net472;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net45;netcoreapp3.1;net5.0</TargetFrameworks>
<Description>A set of helper and extension methods to complement the System.Linq namespace.</Description>
<Authors>Thomas Levesque</Authors>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand All @@ -15,7 +15,7 @@
<AssemblyOriginatorKeyFile>..\..\Linq.Extras.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<MinVerVerbosity>quiet</MinVerVerbosity>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand All @@ -24,35 +24,16 @@
<PackageReference Include="MinVer" Version="2.3.0" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.0'">
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.6'">
<DefineConstants>$(DefineConstants);FEATURE_APPEND_PREPEND</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<DefineConstants>$(DefineConstants);FEATURE_APPEND_PREPEND;FEATURE_ExcludeFromCodeCoverageAttribute</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<DefineConstants>$(DefineConstants);FEATURE_APPEND_PREPEND;FEATURE_TO_HASHSET;FEATURE_NULLABILITY_ATTRIBUTES;FEATURE_ExcludeFromCodeCoverageAttribute</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net45'">
<DefineConstants>$(DefineConstants);FEATURE_ExcludeFromCodeCoverageAttribute</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net471'">
<DefineConstants>$(DefineConstants);FEATURE_APPEND_PREPEND;FEATURE_ExcludeFromCodeCoverageAttribute</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_NULLABILITY_ATTRIBUTES</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net472'">
<DefineConstants>$(DefineConstants);FEATURE_APPEND_PREPEND;FEATURE_TO_HASHSET;FEATURE_ExcludeFromCodeCoverageAttribute</DefineConstants>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<DefineConstants>$(DefineConstants);FEATURE_NULLABILITY_ATTRIBUTES;FEATURE_COMPARER_NULLABILITY</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<DefineConstants>$(DefineConstants);FEATURE_APPEND_PREPEND;FEATURE_TO_HASHSET;FEATURE_ExcludeFromCodeCoverageAttribute</DefineConstants>
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0'">
<DefineConstants>$(DefineConstants);FEATURE_NULLABILITY_ATTRIBUTES;FEATURE_COMPARER_NULLABILITY</DefineConstants>
</PropertyGroup>

</Project>
8 changes: 4 additions & 4 deletions src/Linq.Extras/OuterJoin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static IEnumerable<TResult> LeftOuterJoin<TLeft, TRight, TKey, TResult>(
[NotNull] Func<TLeft, TKey> leftKeySelector,
[NotNull] Func<TRight, TKey> rightKeySelector,
[NotNull] Func<TLeft, TRight, TResult> resultSelector,
TRight defaultRight = default,
TRight defaultRight = default!,
IEqualityComparer<TKey>? keyComparer = null)
{
left.CheckArgumentNull(nameof(left));
Expand Down Expand Up @@ -72,7 +72,7 @@ public static IEnumerable<TResult> RightOuterJoin<TLeft, TRight, TKey, TResult>(
[NotNull] Func<TLeft, TKey> leftKeySelector,
[NotNull] Func<TRight, TKey> rightKeySelector,
[NotNull] Func<TLeft, TRight, TResult> resultSelector,
TLeft defaultLeft = default,
TLeft defaultLeft = default!,
IEqualityComparer<TKey>? keyComparer = null)
{
left.CheckArgumentNull(nameof(left));
Expand Down Expand Up @@ -112,8 +112,8 @@ public static IEnumerable<TResult> FullOuterJoin<TLeft, TRight, TKey, TResult>(
[NotNull] Func<TLeft, TKey> leftKeySelector,
[NotNull] Func<TRight, TKey> rightKeySelector,
[NotNull] Func<TKey, TLeft, TRight, TResult> resultSelector,
TLeft defaultLeft = default,
TRight defaultRight = default,
TLeft defaultLeft = default!,
TRight defaultRight = default!,
IEqualityComparer<TKey>? keyComparer = null)
{
left.CheckArgumentNull(nameof(left));
Expand Down
17 changes: 0 additions & 17 deletions src/Linq.Extras/ToCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,6 @@ public static Stack<TSource> ToStack<TSource>([NotNull] this IEnumerable<TSource
return new Stack<TSource>(source);
}

#if !FEATURE_TO_HASHSET
/// <summary>
/// Creates a hash set from the elements in the source sequence.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <c>source</c>.</typeparam>
/// <param name="source">The sequence containing the elements to put in the hash set.</param>
/// <param name="comparer">A comparer to test for equality between elements.</param>
/// <returns>A hash set containing the same elements as the <c>source</c> sequence.</returns>
/// <remarks>Since a hash set cannot contain duplicates, duplicate elements from the <c>source</c> sequence will not be included in the hash set.</remarks>
[Pure]
public static HashSet<TSource> ToHashSet<TSource>([NotNull] this IEnumerable<TSource> source, IEqualityComparer<TSource>? comparer = null)
{
source.CheckArgumentNull(nameof(source));
return new HashSet<TSource>(source, comparer);
}
#endif

/// <summary>
/// Creates a linked list from the elements in the source sequence.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Linq.Extras/ToHierarchy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static IEnumerable<INode<TSource>> ToHierarchy<TSource, TId>(
[NotNull] this IEnumerable<TSource> source,
[NotNull] Func<TSource, TId> idSelector,
[NotNull] Func<TSource, TId> parentIdSelector,
TId rootParentId = default)
TId rootParentId = default!)
{
source.CheckArgumentNull(nameof(source));
idSelector.CheckArgumentNull(nameof(idSelector));
Expand Down
22 changes: 20 additions & 2 deletions src/Linq.Extras/XComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,15 @@ public ByKeyComparer(Func<T, TKey> keySelector, IComparer<TKey>? keyComparer)
_keyComparer = keyComparer ?? Comparer<TKey>.Default;
}

#if FEATURE_COMPARER_NULLABILITY
public int Compare(T? x, T? y)
#else
public int Compare(T x, T y)
#endif
{
return _keyComparer.Compare(_keySelector(x), _keySelector(y));
return _keyComparer.Compare(
x is null ? default! : _keySelector(x),
y is null ? default! : _keySelector(y));
}
}

Expand All @@ -197,7 +203,11 @@ public ReverseComparer(IComparer<T> baseComparer)
_baseComparer = baseComparer;
}

#if FEATURE_COMPARER_NULLABILITY
public int Compare(T? x, T? y)
#else
public int Compare(T x, T y)
#endif
{
return _baseComparer.Compare(y, x);
}
Expand All @@ -217,7 +227,11 @@ public ChainedComparer(IEnumerable<IComparer<T>> comparers)
Comparers = comparers.ToArray();
}

#if FEATURE_COMPARER_NULLABILITY
public int Compare(T? x, T? y)
#else
public int Compare(T x, T y)
#endif
{
return Comparers.Select(comparer => comparer.Compare(x, y)).FirstOrDefault(cmp => cmp != 0);
}
Expand All @@ -232,10 +246,14 @@ public DelegateComparer(Comparison<T> comparison)
_comparison = comparison;
}

#if FEATURE_COMPARER_NULLABILITY
public int Compare(T? x, T? y) => _comparison(x!, y!);
#else
public int Compare(T x, T y) => _comparison(x, y);
#endif
}

#endregion
#endregion

}

Expand Down
13 changes: 10 additions & 3 deletions src/Linq.Extras/XEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,25 @@ public ByKeyEqualityComparer(Func<TSource, TKey> keySelector, IEqualityComparer<
_keyComparer = keyComparer ?? EqualityComparer<TKey>.Default;
}

#if FEATURE_COMPARER_NULLABILITY
public bool Equals(TSource? x, TSource? y)
#else
public bool Equals(TSource x, TSource y)
#endif
{
return _keyComparer.Equals(_keySelector(x), _keySelector(y));
return _keyComparer.Equals(
x is null ? default! : _keySelector(x),
y is null ? default! : _keySelector(y));
}

public int GetHashCode(TSource obj)
{
return _keyComparer.GetHashCode(_keySelector(obj));
var key = _keySelector(obj);
return key is null ? 0 : _keyComparer.GetHashCode(key);
}
}

#endregion
#endregion
}

/// <summary>
Expand Down
13 changes: 6 additions & 7 deletions tests/Linq.Extras.Tests/Linq.Extras.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp1.0;netcoreapp2.1;netcoreapp3.1;net461</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net461;net5.0</TargetFrameworks>
<DebugType Condition="'$(TargetFramework)' != '' AND '$(TargetFramework)' != 'netcoreapp1.0'">Full</DebugType>
<AssemblyOriginatorKeyFile>..\..\Linq.Extras.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand All @@ -21,16 +21,15 @@
<ProjectReference Include="../../src/Linq.Extras/Linq.Extras.csproj" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp1.0'">
<DefineConstants>$(DefineConstants);FEATURE_APPEND_PREPEND</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<DefineConstants>$(DefineConstants);FEATURE_APPEND_PREPEND;FEATURE_TO_HASHSET</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<DefineConstants>$(DefineConstants);FEATURE_APPEND_PREPEND;FEATURE_TO_HASHSET;FEATURE_ICOMPARER_NULLABILITY</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_ICOMPARER_NULLABILITY</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0'">
<DefineConstants>$(DefineConstants);FEATURE_ICOMPARER_NULLABILITY</DefineConstants>
</PropertyGroup>

</Project>
6 changes: 3 additions & 3 deletions tests/Linq.Extras.Tests/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ public static void AssertThrowsWhenArgumentNull(Expression<Action> expr)
var parameters = method.GetParameters();
var paramIndexes = parameters
.Select((p, i) => new { p, i })
.ToDictionary(x => x.p.Name, x => x.i);
.ToDictionary(x => x.p.Name!, x => x.i);
var paramTypes = parameters
.ToDictionary(p => p.Name, p => p.ParameterType);
.ToDictionary(p => p.Name!, p => p.ParameterType);

var nonNullableRefParams = parameters
.Where(p => !p.ParameterType.GetTypeInfo().IsValueType && GetNullability(p, defaultNullability) == Nullability.NotNull);

foreach (var param in nonNullableRefParams)
{
var paramName = param.Name;
var paramName = param.Name!;
var args = realArgs.ToArray();
args[paramIndexes[paramName]] = Expression.Constant(null, paramTypes[paramName]);
var call = Expression.Call(realCall.Object, method, args);
Expand Down
46 changes: 0 additions & 46 deletions tests/Linq.Extras.Tests/XEnumerableTests/AppendPrependTests.cs

This file was deleted.

Loading

0 comments on commit 6d4f81a

Please sign in to comment.