Skip to content

Commit 94d2804

Browse files
authored
Merge pull request #319 from w-ahmad/fix/nested_property_sorting
fix: Nested property sorting
2 parents 3047d7f + db8daa1 commit 94d2804

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/ItemsSource/ColumnSortDescription.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ColumnSortDescription(TableViewColumn column,
2222
public override object? GetPropertyValue(object? item)
2323
{
2424
// Use reflection-based property access when SortMemberPath is explicitly provided; otherwise, fall back to column cell content.
25-
if (!string.IsNullOrEmpty(PropertyName))
25+
if (!string.IsNullOrEmpty(Column.SortMemberPath))
2626
{
2727
return base.GetPropertyValue(item);
2828
}

src/ItemsSource/SortDescription.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using WinUI.TableView.Extensions;
45

56
namespace WinUI.TableView;
67

@@ -9,6 +10,8 @@ namespace WinUI.TableView;
910
/// </summary>
1011
public class SortDescription
1112
{
13+
private Func<object, object?>? _funcCompiled;
14+
1215
/// <summary>
1316
/// Initializes a new instance of the <see cref="SortDescription"/> class that describes
1417
/// a sort on the object itself
@@ -35,21 +38,15 @@ public SortDescription(string? propertyName,
3538
/// <returns>The value of the property.</returns>
3639
public virtual object? GetPropertyValue(object? item)
3740
{
38-
if (ValueDelegate is not null)
39-
{
40-
return ValueDelegate(item);
41-
}
42-
else if (PropertyName is not null)
43-
{
44-
return item?.GetType()
45-
.GetProperty(PropertyName)?
46-
.GetValue(item);
47-
}
48-
else
49-
{
50-
return default!;
51-
}
52-
}
41+
if (item == null) return null;
42+
43+
if (ValueDelegate is not null) return ValueDelegate(item);
44+
45+
if (_funcCompiled is null && !string.IsNullOrWhiteSpace(PropertyName))
46+
_funcCompiled = item.GetFuncCompiledPropertyPath(PropertyName!);
47+
48+
return _funcCompiled?.Invoke(item);
49+
}
5350

5451
/// <summary>
5552
/// Compares two objects based on the sort description.

0 commit comments

Comments
 (0)