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