Skip to content

Commit 38462ab

Browse files
committed
Added support for string indexers in the Property path
Signed-off-by: Daniël Trommel <[email protected]>
1 parent bd5d6c1 commit 38462ab

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Extensions/ObjectExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ internal static partial class ObjectExtensions
9898

9999
if (part.StartsWith('[') && part.EndsWith(']'))
100100
{
101-
// Indexer: [index] or [key]
101+
// Indexer: [int] or [string]
102102
string indexer = part[1..^1];
103103
if (int.TryParse(indexer, out int intIndex))
104104
index = intIndex;
@@ -123,8 +123,9 @@ internal static partial class ObjectExtensions
123123
continue;
124124
}
125125

126-
// Try default indexer property (e.g., this[string])
127-
pi = currentType?.GetProperty("Item");
126+
// Try to find a default indexer property "Item" (e.g., this[string]);
127+
// Note that only single argument indexers of type int or string are currently support
128+
pi = currentType?.GetProperty("Item", [index.GetType()]);
128129
if (pi != null)
129130
{
130131
current = pi.GetValue(current, [index]);

0 commit comments

Comments
 (0)