@@ -33,23 +33,23 @@ public ComposedDocNode(DocNodeType type, int size = -1, string sourceInformation
33
33
/// access the node as if it was a list
34
34
public override DocNode this [ int index ] {
35
35
get {
36
- CheckTypeIs ( DocNodeType . List ) ;
36
+ AssertTypeIs ( DocNodeType . List ) ;
37
37
return list [ index ] ;
38
38
}
39
39
set {
40
- CheckTypeIs ( DocNodeType . List ) ;
40
+ AssertTypeIs ( DocNodeType . List ) ;
41
41
list [ index ] = value ;
42
42
}
43
43
}
44
44
45
45
/// access the node as if it was a Dictionary
46
46
public override DocNode this [ string key ] {
47
47
get {
48
- CheckTypeIs ( DocNodeType . Dictionary ) ;
48
+ AssertTypeIs ( DocNodeType . Dictionary ) ;
49
49
return dictionary [ key ] ;
50
50
}
51
51
set {
52
- CheckTypeIs ( DocNodeType . Dictionary ) ;
52
+ AssertTypeIs ( DocNodeType . Dictionary ) ;
53
53
dictionary [ key ] = value ;
54
54
}
55
55
}
@@ -58,11 +58,11 @@ public override DocNode this[string key] {
58
58
Type switch {
59
59
DocNodeType . Dictionary => dictionary . Count ,
60
60
DocNodeType . List => list . Count ,
61
- _ => throw new DocNodeAccessException ( GenerateAccessExceptionMessage ( "Countable (Dictionary or List)" ) )
61
+ _ => throw new DocNodeAccessException ( GenerateAccessExceptionMessage ( "Countable (Dictionary or List)" , Type . ToString ( ) ) )
62
62
} ;
63
63
64
64
public override bool ContainsKey ( string key , bool ignoreCase = false ) {
65
- CheckTypeIs ( DocNodeType . Dictionary ) ;
65
+ AssertTypeIs ( DocNodeType . Dictionary ) ;
66
66
foreach ( string dictKey in dictionary . Keys ) {
67
67
if ( string . Equals ( dictKey , key , ignoreCase ? StringComparison . OrdinalIgnoreCase : StringComparison . Ordinal ) ) {
68
68
return true ;
@@ -72,7 +72,7 @@ public override bool ContainsKey(string key, bool ignoreCase = false) {
72
72
}
73
73
74
74
public override bool TryGetValue ( string key , bool ignoreCase , out DocNode result ) {
75
- CheckTypeIs ( DocNodeType . Dictionary ) ;
75
+ AssertTypeIs ( DocNodeType . Dictionary ) ;
76
76
foreach ( var kvp in dictionary ) {
77
77
if ( string . Equals ( kvp . Key , key , ignoreCase ? StringComparison . OrdinalIgnoreCase : StringComparison . Ordinal ) ) {
78
78
result = kvp . Value ;
@@ -86,25 +86,25 @@ public override bool TryGetValue(string key, bool ignoreCase, out DocNode result
86
86
87
87
public override IEnumerable < DocNode > Values {
88
88
get {
89
- CheckTypeIs ( DocNodeType . List ) ;
89
+ AssertTypeIs ( DocNodeType . List ) ;
90
90
return list ;
91
91
}
92
92
}
93
93
94
94
public override IEnumerable < KeyValuePair < string , DocNode > > Pairs {
95
95
get {
96
- CheckTypeIs ( DocNodeType . Dictionary ) ;
96
+ AssertTypeIs ( DocNodeType . Dictionary ) ;
97
97
return dictionary ;
98
98
}
99
99
}
100
100
101
101
public override string StringValue {
102
102
get {
103
- CheckTypeIs ( DocNodeType . Scalar ) ;
103
+ AssertTypeIs ( DocNodeType . Scalar ) ;
104
104
return scalar ;
105
105
}
106
106
set {
107
- CheckTypeIs ( DocNodeType . Scalar ) ;
107
+ AssertTypeIs ( DocNodeType . Scalar ) ;
108
108
scalar = value ;
109
109
}
110
110
}
@@ -119,32 +119,32 @@ public override string ToString() {
119
119
#endregion
120
120
121
121
public void Add ( DocNode d ) {
122
- CheckTypeIs ( DocNodeType . List ) ;
122
+ AssertTypeIs ( DocNodeType . List ) ;
123
123
list . Add ( d ) ;
124
124
}
125
125
126
126
public void Add ( string key , DocNode value ) {
127
- CheckTypeIs ( DocNodeType . Dictionary ) ;
127
+ AssertTypeIs ( DocNodeType . Dictionary ) ;
128
128
dictionary . Add ( key , value ) ;
129
129
}
130
130
131
131
public void InsertAt ( int index , DocNode value ) {
132
- CheckTypeIs ( DocNodeType . List ) ;
132
+ AssertTypeIs ( DocNodeType . List ) ;
133
133
list . Insert ( index , value ) ;
134
134
}
135
135
136
136
public void Remove ( DocNode d ) {
137
- CheckTypeIs ( DocNodeType . List ) ;
137
+ AssertTypeIs ( DocNodeType . List ) ;
138
138
list . Remove ( d ) ;
139
139
}
140
140
141
141
public void RemoveAt ( int index ) {
142
- CheckTypeIs ( DocNodeType . List ) ;
142
+ AssertTypeIs ( DocNodeType . List ) ;
143
143
list . RemoveAt ( index ) ;
144
144
}
145
145
146
146
public void RemoveKey ( string key ) {
147
- CheckTypeIs ( DocNodeType . Dictionary ) ;
147
+ AssertTypeIs ( DocNodeType . Dictionary ) ;
148
148
dictionary . Remove ( key ) ;
149
149
}
150
150
@@ -205,17 +205,5 @@ public static ComposedDocNode MakeMutableRef(ref DocNode doc, bool recursive = t
205
205
public static ComposedDocNode DeepClone ( DocNode doc ) {
206
206
return MakeMutable ( doc , recursive : true , force : true ) ;
207
207
}
208
-
209
- /////////////////////////////////////////////////
210
-
211
- void CheckTypeIs ( DocNodeType requiredType ) {
212
- if ( Type != requiredType ) {
213
- throw new DocNodeAccessException ( GenerateAccessExceptionMessage ( requiredType . ToString ( ) ) ) ;
214
- }
215
- }
216
-
217
- string GenerateAccessExceptionMessage ( string expectedType ) {
218
- return $ "Accessing ComposedDocNode as { expectedType } but is { Type } . ";
219
- }
220
208
}
221
209
}
0 commit comments