-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract QueryableExtensions into own NuGet package (#37)
- Loading branch information
Tomas Lycken
authored
Nov 1, 2017
1 parent
81238d3
commit fd9ef32
Showing
6 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace tlycken.Extensions.Tests | ||
{ | ||
public class QueryableExtensions | ||
{ | ||
public class Foo | ||
{ | ||
public bool Bar { get; set; } | ||
} | ||
|
||
[Fact] | ||
public void CanApplyProjectionToQueryables() | ||
{ | ||
var foos = new[] { new Foo { Bar = true }, new Foo { Bar = false }, new Foo { Bar = true } }.AsQueryable(); | ||
|
||
var result = foos.Apply(fs => fs.Where(foo => foo.Bar)); | ||
|
||
Assert.Equal(2, result.Count()); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/tlycken.Extensions.Tests/tlycken.Extensions.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" /> | ||
<PackageReference Include="xunit" Version="2.2.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\tlycken.Extensions\tlycken.Extensions.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// ReSharper disable once CheckNamespace | ||
namespace System | ||
{ | ||
public static class FuncExtensions | ||
{ | ||
/// <summary> | ||
/// Fluently applies the function <paramref name="projection"/> to the argument <paramref name="source"/>. | ||
/// </summary> | ||
/// <remarks>My main use case for this as an abstraction for queryables, taking a | ||
/// <code>Func{IQueryable{S}, IQueryable{T}}</code> as an argument and applying it | ||
/// in a longer LINQ method chain.</remarks> | ||
/// <typeparam name="S">The element type of the queryable sequence</typeparam> | ||
/// <typeparam name="T">The element type of the result</typeparam> | ||
/// <param name="source">The source sequence</param> | ||
/// <param name="projection">A projection to apply to the <paramref name="source"/> sequence</param> | ||
/// <returns>projection(source)</returns> | ||
public static T Apply<S, T>(this S source, Func<S, T> projection) => projection(source); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |