Skip to content

Commit 1a324ab

Browse files
committed
Revert "elevate values from array binding"
This reverts commit 417ae32.
1 parent 417ae32 commit 1a324ab

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

src/Columns/TableViewBoundColumn.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ public abstract class TableViewBoundColumn : TableViewColumn
1414
private Type? _listType;
1515
private string? _propertyPath;
1616
private Binding _binding = new();
17-
private (MemberInfo, object?)[]? _memberInfo;
17+
private (PropertyInfo, object?)[]? _propertyInfo;
1818

1919
public override object? GetCellContent(object? dataItem)
2020
{
2121
if (dataItem is null) return null;
2222

23-
if (_memberInfo is null || dataItem.GetType() != _listType)
23+
if (_propertyInfo is null || dataItem.GetType() != _listType)
2424
{
2525
_listType = dataItem.GetType();
26-
dataItem = dataItem.GetValue(_listType, PropertyPath, out _memberInfo);
26+
dataItem = dataItem.GetValue(_listType, PropertyPath, out _propertyInfo);
2727
}
2828
else
2929
{
30-
dataItem = dataItem.GetValue(_memberInfo);
30+
dataItem = dataItem.GetValue(_propertyInfo);
3131
}
3232

3333
if (Binding?.Converter is not null)

src/Extensions/ObjectExtensions.cs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,18 @@ internal static class ObjectExtensions
1212
/// Gets the value of a property from an object using a sequence of property info and index pairs.
1313
/// </summary>
1414
/// <param name="obj">The object from which to get the value.</param>
15-
/// <param name="members">An array of member info and index pairs.</param>
15+
/// <param name="pis">An array of property info and index pairs.</param>
1616
/// <returns>The value of the property, or null if the object is null.</returns>
17-
internal static object? GetValue(this object? obj, (MemberInfo info, object? index)[] members)
17+
internal static object? GetValue(this object? obj, (PropertyInfo pi, object? index)[] pis)
1818
{
19-
foreach (var (info, index) in members)
19+
foreach (var pi in pis)
2020
{
2121
if (obj is null)
2222
{
2323
break;
2424
}
2525

26-
if (info is PropertyInfo pi)
27-
obj = index is not null ? pi.GetValue(obj, [index]) : pi.GetValue(obj);
28-
else if (info is MethodInfo mi)
29-
obj = index is not null ? mi.Invoke(obj, [index]) : mi.Invoke(obj, []);
26+
obj = pi.index is not null ? pi.pi.GetValue(obj, [pi.index]) : pi.pi.GetValue(obj);
3027
}
3128

3229
return obj;
@@ -38,19 +35,19 @@ internal static class ObjectExtensions
3835
/// <param name="obj">The object from which to get the value.</param>
3936
/// <param name="type">The type of the object.</param>
4037
/// <param name="path">The property path.</param>
41-
/// <param name="members">An array of member info and index pairs.</param>
38+
/// <param name="pis">An array of property info and index pairs.</param>
4239
/// <returns>The value of the property, or null if the object is null.</returns>
43-
internal static object? GetValue(this object? obj, Type? type, string? path, out (MemberInfo info, object? index)[] members)
40+
internal static object? GetValue(this object? obj, Type? type, string? path, out (PropertyInfo pi, object? index)[] pis)
4441
{
4542
var parts = path?.Split('.');
4643

4744
if (parts is null)
4845
{
49-
members = [];
46+
pis = [];
5047
return obj;
5148
}
5249

53-
members = new (MemberInfo, object?)[parts.Length];
50+
pis = new (PropertyInfo, object?)[parts.Length];
5451

5552
for (var i = 0; i < parts.Length; i++)
5653
{
@@ -62,22 +59,16 @@ internal static class ObjectExtensions
6259
part = "Item";
6360
}
6461

65-
if (type?.GetProperty(part) is { } pi)
62+
var pi = type?.GetProperty(part);
63+
if (pi is not null)
6664
{
67-
members[i] = (pi, index);
65+
pis[i] = (pi, index);
6866
obj = index is not null ? pi?.GetValue(obj, [index]) : pi?.GetValue(obj);
6967
type = obj?.GetType();
7068
}
71-
else if (type?.IsArray is true && type.GetMethod("GetValue", [typeof(int)]) is { } mi)
72-
{
73-
members[i] = (mi, index);
74-
obj = index is not null ? mi?.Invoke(obj, [index]) : mi?.Invoke(obj, []);
75-
type = obj?.GetType();
76-
77-
}
7869
else
7970
{
80-
members = null!;
71+
pis = null!;
8172
return null;
8273
}
8374
}

0 commit comments

Comments
 (0)