Skip to content

Commit

Permalink
Add OrderBy and OrderByDescending
Browse files Browse the repository at this point in the history
  • Loading branch information
aaubry committed Oct 15, 2024
1 parent cf3b800 commit 84e883e
Show file tree
Hide file tree
Showing 11 changed files with 1,038 additions and 2,452 deletions.
39 changes: 39 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Microsoft Public License (Ms-PL)

## In this article

1. [1. Definitions](#1-definitions)
2. [2. Grant of Rights](#2-grant-of-rights)
3. [3. Conditions and Limitations](#3-conditions-and-limitations)

**This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.**

[](https://learn.microsoft.com/en-us/previous-versions/bb894665(v=msdn.10)?redirectedfrom=MSDN#1-definitions)

## 1. Definitions

The terms “reproduce,” “reproduction,” “derivative works,” and “distribution” have the same meaning here as under U.S. copyright law.

A “contribution” is the original software, or any additions or changes to the software.

A “contributor” is any person that distributes its contribution under this license.

“Licensed patents” are a contributor’s patent claims that read directly on its contribution.

## 2. Grant of Rights

(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.

(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.

## 3. Conditions and Limitations

(A) No Trademark License- This license does not grant you rights to use any contributors’ name, logo, or trademarks.

(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.

(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.

(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.

(E) The software is licensed “as-is.” You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
472 changes: 471 additions & 1 deletion README.md

Large diffs are not rendered by default.

49 changes: 44 additions & 5 deletions System.Linq.Dynamic.Tests/DynamicExpressionTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Xunit;
using DynamicExpression = System.Linq.Dynamic.DynamicExpression;

namespace System.Linq.Dynamic.Tests
{
Expand All @@ -23,7 +20,7 @@ public void ParseSimpleExpressionWorks()

var results = values.Where(expr).ToList();

Assert.Equal(1, results.Count);
Assert.Single(results);
Assert.Equal("food", results[0]);
}

Expand Down Expand Up @@ -323,6 +320,48 @@ private class Item
public string Name { get; set; }
public string Title { get; set; }
}

[Fact]
public void CanInvokeOrderBy()
{
var expr = DynamicExpression.ParseLambda<IEnumerable<Item>, IEnumerable>("it.OrderBy(Name)");
var func = expr.Compile();

var res = func(new[]
{
new Item { Id = 1, Name = "c", Title = "title one" },
new Item { Id = 2, Name = "a", Title = "title two" },
new Item { Id = 3, Name = "b", Title = "title two" },
});

var mappedItems = res.Cast<dynamic>().ToList();
Assert.Equal(3, mappedItems.Count);

Assert.Equal(2, mappedItems[0].Id);
Assert.Equal(3, mappedItems[1].Id);
Assert.Equal(1, mappedItems[2].Id);
}

[Fact]
public void CanInvokeOrderByDescending()
{
var expr = DynamicExpression.ParseLambda<IEnumerable<Item>, IEnumerable>("it.OrderByDescending(Name)");
var func = expr.Compile();

var res = func(new[]
{
new Item { Id = 1, Name = "c", Title = "title one" },
new Item { Id = 2, Name = "a", Title = "title two" },
new Item { Id = 3, Name = "b", Title = "title two" },
});

var mappedItems = res.Cast<dynamic>().ToList();
Assert.Equal(3, mappedItems.Count);

Assert.Equal(1, mappedItems[0].Id);
Assert.Equal(3, mappedItems[1].Id);
Assert.Equal(2, mappedItems[2].Id);
}
}

public enum MyEnum
Expand Down
11 changes: 7 additions & 4 deletions System.Linq.Dynamic.Tests/System.Linq.Dynamic.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net8</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 84e883e

Please sign in to comment.