@@ -6,45 +6,45 @@ abstract class Condition(bool reversed, string? fieldExpression)
6
6
protected readonly bool reversed = reversed ;
7
7
protected readonly string ? fieldExpression = fieldExpression ;
8
8
9
- private static void HandleField ( object o , string field , List < object ? > fields ) {
10
- fields . Add ( o . GetType ( ) . GetField ( field ) ! . GetValue ( o ) ) ;
9
+ private static void HandleField ( object obj , string field , List < object ? > values ) {
10
+ values . Add ( obj . GetType ( ) . GetField ( field ) ! . GetValue ( obj ) ) ;
11
11
}
12
12
13
- private static void HandleIndex ( IList list , int index , List < object ? > fields ) {
14
- fields . Add ( list [ index ] ) ;
13
+ private static void HandleIndex ( IList list , int index , List < object ? > values ) {
14
+ values . Add ( list [ index ] ) ;
15
15
}
16
16
17
- private static void HandleKey ( IDictionary map , string key , List < object ? > fields ) {
18
- fields . Add ( map [ key ] ) ;
17
+ private static void HandleKey ( IDictionary map , string key , List < object ? > values ) {
18
+ values . Add ( map [ key ] ) ;
19
19
}
20
20
21
- private static void HandleFields ( List < object ? > fields , string name , List < object ? > newFields ) {
22
- foreach ( object ? o in fields )
23
- if ( o == null )
24
- newFields . Add ( null ) ;
25
- else if ( o is IDictionary d )
26
- HandleKey ( d , name , newFields ) ;
27
- else if ( o is IList l && int . TryParse ( name , out int index ) )
28
- HandleIndex ( l , index , newFields ) ;
21
+ private static void HandleValues ( List < object ? > values , string name , List < object ? > newValues ) {
22
+ foreach ( object ? value in values )
23
+ if ( value == null )
24
+ newValues . Add ( null ) ;
25
+ else if ( value is IDictionary d )
26
+ HandleKey ( d , name , newValues ) ;
27
+ else if ( value is IList l && int . TryParse ( name , out int index ) )
28
+ HandleIndex ( l , index , newValues ) ;
29
29
else
30
- HandleField ( o , name , newFields ) ;
30
+ HandleField ( value , name , newValues ) ;
31
31
}
32
32
33
33
internal bool Check ( object ? root , string ? rootFieldExpression , HashSet < string > passedFields , HashSet < string > failedFields ) {
34
- List < object ? > fields = [ root ] ;
34
+ List < object ? > values = [ root ] ;
35
35
if ( fieldExpression != null ) {
36
36
if ( root != null ) {
37
37
string fullName = "" ;
38
38
foreach ( string name in fieldExpression . Split ( '.' ) ) {
39
- List < object ? > newFields = [ ] ;
39
+ List < object ? > newValues = [ ] ;
40
40
fullName += name ;
41
41
if ( fullName == "*" )
42
- foreach ( object ? o in fields )
42
+ foreach ( object ? o in values )
43
43
if ( o == null )
44
- newFields . Add ( null ) ;
44
+ newValues . Add ( null ) ;
45
45
else if ( o is IEnumerable e )
46
46
foreach ( object item in e )
47
- newFields . Add ( item ) ;
47
+ newValues . Add ( item ) ;
48
48
else
49
49
throw new Exception ( "Unsupported type for iteration: " + o . GetType ( ) ) ;
50
50
else if ( name . Length >= 3 && name [ ^ 3 ..^ 1 ] == "//" )
@@ -56,35 +56,35 @@ internal bool Check(object? root, string? rootFieldExpression, HashSet<string> p
56
56
fullName += "." ;
57
57
continue ;
58
58
case 'F' :
59
- foreach ( object ? o in fields )
59
+ foreach ( object ? o in values )
60
60
if ( o == null )
61
- newFields . Add ( null ) ;
61
+ newValues . Add ( null ) ;
62
62
else
63
- HandleField ( o , fullName , newFields ) ;
63
+ HandleField ( o , fullName , newValues ) ;
64
64
break ;
65
65
case 'I' :
66
- foreach ( object ? o in fields )
66
+ foreach ( object ? o in values )
67
67
if ( o == null )
68
- newFields . Add ( null ) ;
68
+ newValues . Add ( null ) ;
69
69
else
70
- HandleIndex ( ( IList ) o , int . Parse ( fullName ) , newFields ) ;
70
+ HandleIndex ( ( IList ) o , int . Parse ( fullName ) , newValues ) ;
71
71
break ;
72
72
case 'K' :
73
- foreach ( object ? o in fields )
73
+ foreach ( object ? o in values )
74
74
if ( o == null )
75
- newFields . Add ( null ) ;
75
+ newValues . Add ( null ) ;
76
76
else
77
- HandleKey ( ( IDictionary ) o , fullName , newFields ) ;
77
+ HandleKey ( ( IDictionary ) o , fullName , newValues ) ;
78
78
break ;
79
79
case '*' :
80
- HandleFields ( fields , fullName + "*" , newFields ) ;
80
+ HandleValues ( values , fullName + "*" , newValues ) ;
81
81
break ;
82
82
default :
83
83
throw new Exception ( "Unsupported suffix: " + name [ ^ 1 ] ) ;
84
84
}
85
85
} else
86
- HandleFields ( fields , name , newFields ) ;
87
- fields = newFields ;
86
+ HandleValues ( values , name , newValues ) ;
87
+ values = newValues ;
88
88
fullName = "" ;
89
89
}
90
90
}
@@ -94,8 +94,8 @@ internal bool Check(object? root, string? rootFieldExpression, HashSet<string> p
94
94
rootFieldExpression = fieldExpression ;
95
95
}
96
96
HashSet < string > childPassedFields = [ ] , childFailedFields = [ ] ;
97
- foreach ( object ? field in fields )
98
- if ( IsFulfilledBy ( field , rootFieldExpression , childPassedFields , childFailedFields ) == reversed ) {
97
+ foreach ( object ? value in values )
98
+ if ( IsFulfilledBy ( value , rootFieldExpression , childPassedFields , childFailedFields ) == reversed ) {
99
99
if ( rootFieldExpression != null )
100
100
failedFields . Add ( rootFieldExpression ) ;
101
101
if ( reversed )
@@ -113,5 +113,5 @@ internal bool Check(object? root, string? rootFieldExpression, HashSet<string> p
113
113
return true ;
114
114
}
115
115
116
- protected abstract bool IsFulfilledBy ( object ? field , string ? fullFieldExpression , HashSet < string > passedFields , HashSet < string > failedFields ) ;
116
+ protected abstract bool IsFulfilledBy ( object ? value , string ? fullFieldExpression , HashSet < string > passedFields , HashSet < string > failedFields ) ;
117
117
}
0 commit comments