Skip to content

Commit 54660ef

Browse files
committed
918 (DataColumnOrdinalIgnoreCaseComparer)
1 parent 195bc16 commit 54660ef

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
66
<RootNamespace>ConsoleApp_net6._0</RootNamespace>
77
<Nullable>enable</Nullable>
8+
<LangVersion>12</LangVersion>
89
</PropertyGroup>
910

1011
<ItemGroup>
11-
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core.NewtonsoftJson\System.Linq.Dynamic.Core.NewtonsoftJson.csproj" />
12-
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core.SystemTextJson\System.Linq.Dynamic.Core.SystemTextJson.csproj" />
12+
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core.NewtonsoftJson\System.Linq.Dynamic.Core.NewtonsoftJson.csproj" />
13+
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core.SystemTextJson\System.Linq.Dynamic.Core.SystemTextJson.csproj" />
1314
</ItemGroup>
1415

15-
</Project>
16+
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections;
3+
4+
namespace ConsoleApp_net6._0;
5+
6+
public class DataColumnOrdinalIgnoreCaseComparer : IComparer
7+
{
8+
public int Compare(object? x, object? y)
9+
{
10+
if (x == null && y == null)
11+
{
12+
return 0;
13+
}
14+
15+
if (x == null)
16+
{
17+
return -1;
18+
}
19+
20+
if (y == null)
21+
{
22+
return 1;
23+
}
24+
25+
if (x is string xAsString && y is string yAsString)
26+
{
27+
return StringComparer.OrdinalIgnoreCase.Compare(xAsString, yAsString);
28+
}
29+
30+
return Comparer.Default.Compare(x, y);
31+
}
32+
}

src-console/ConsoleApp_net6.0/Program.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ class Program
4141
{
4242
static void Main(string[] args)
4343
{
44-
Q912a();
45-
Q912b();
44+
Issue918();
45+
return;
46+
47+
Issue912a();
48+
Issue912b();
4649
return;
4750

4851
Json();
@@ -68,7 +71,33 @@ static void Main(string[] args)
6871
Dynamic();
6972
}
7073

71-
private static void Q912a()
74+
private static void Issue918()
75+
{
76+
var persons = new DataTable();
77+
persons.Columns.Add("FirstName", typeof(string));
78+
persons.Columns.Add("Nickname", typeof(string));
79+
persons.Columns.Add("Income", typeof(decimal)).AllowDBNull = true;
80+
81+
// Adding sample data to the first DataTable
82+
persons.Rows.Add("alex", DBNull.Value, 5000.50m);
83+
persons.Rows.Add("MAGNUS", "Mag", 5000.50m);
84+
persons.Rows.Add("Terry", "Ter", 4000.20m);
85+
persons.Rows.Add("Charlotte", "Charl", DBNull.Value);
86+
87+
var linqQuery =
88+
from personsRow in persons.AsEnumerable()
89+
select personsRow;
90+
91+
var queryableRows = linqQuery.AsQueryable();
92+
93+
// Sorted at the top of the list
94+
var comparer = new DataColumnOrdinalIgnoreCaseComparer();
95+
var sortedRows = queryableRows.OrderBy("FirstName", comparer).ToList();
96+
97+
int xxx = 0;
98+
}
99+
100+
private static void Issue912a()
72101
{
73102
var extractedRows = new List<SalesData>
74103
{
@@ -97,7 +126,7 @@ private static void Q912a()
97126
int x = 9;
98127
}
99128

100-
private static void Q912b()
129+
private static void Issue912b()
101130
{
102131
var eInfoJoinTable = new DataTable();
103132
eInfoJoinTable.Columns.Add("Region", typeof(string));

0 commit comments

Comments
 (0)