@@ -12,18 +12,21 @@ internal static class ObjectExtensions
12
12
/// Gets the value of a property from an object using a sequence of property info and index pairs.
13
13
/// </summary>
14
14
/// <param name="obj">The object from which to get the value.</param>
15
- /// <param name="pis ">An array of property info and index pairs.</param>
15
+ /// <param name="members ">An array of member info and index pairs.</param>
16
16
/// <returns>The value of the property, or null if the object is null.</returns>
17
- internal static object ? GetValue ( this object ? obj , ( PropertyInfo pi , object ? index ) [ ] pis )
17
+ internal static object ? GetValue ( this object ? obj , ( MemberInfo info , object ? index ) [ ] members )
18
18
{
19
- foreach ( var pi in pis )
19
+ foreach ( var ( info , index ) in members )
20
20
{
21
21
if ( obj is null )
22
22
{
23
23
break ;
24
24
}
25
25
26
- obj = pi . index is not null ? pi . pi . GetValue ( obj , [ pi . index ] ) : pi . pi . GetValue ( obj ) ;
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 , [ ] ) ;
27
30
}
28
31
29
32
return obj ;
@@ -35,19 +38,19 @@ internal static class ObjectExtensions
35
38
/// <param name="obj">The object from which to get the value.</param>
36
39
/// <param name="type">The type of the object.</param>
37
40
/// <param name="path">The property path.</param>
38
- /// <param name="pis ">An array of property info and index pairs.</param>
41
+ /// <param name="members ">An array of member info and index pairs.</param>
39
42
/// <returns>The value of the property, or null if the object is null.</returns>
40
- internal static object ? GetValue ( this object ? obj , Type ? type , string ? path , out ( PropertyInfo pi , object ? index ) [ ] pis )
43
+ internal static object ? GetValue ( this object ? obj , Type ? type , string ? path , out ( MemberInfo info , object ? index ) [ ] members )
41
44
{
42
45
var parts = path ? . Split ( '.' ) ;
43
46
44
47
if ( parts is null )
45
48
{
46
- pis = [ ] ;
49
+ members = [ ] ;
47
50
return obj ;
48
51
}
49
52
50
- pis = new ( PropertyInfo , object ? ) [ parts . Length ] ;
53
+ members = new ( MemberInfo , object ? ) [ parts . Length ] ;
51
54
52
55
for ( var i = 0 ; i < parts . Length ; i ++ )
53
56
{
@@ -59,16 +62,22 @@ internal static class ObjectExtensions
59
62
part = "Item" ;
60
63
}
61
64
62
- var pi = type ? . GetProperty ( part ) ;
63
- if ( pi is not null )
65
+ if ( type ? . GetProperty ( part ) is { } pi )
64
66
{
65
- pis [ i ] = ( pi , index ) ;
67
+ members [ i ] = ( pi , index ) ;
66
68
obj = index is not null ? pi ? . GetValue ( obj , [ index ] ) : pi ? . GetValue ( obj ) ;
67
69
type = obj ? . GetType ( ) ;
68
70
}
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
+ }
69
78
else
70
79
{
71
- pis = null ! ;
80
+ members = null ! ;
72
81
return null ;
73
82
}
74
83
}
0 commit comments