@@ -181,62 +181,73 @@ private static VariableDetails[] GetChildren(object obj)
181
181
IDictionary dictionary = obj as IDictionary ;
182
182
IEnumerable enumerable = obj as IEnumerable ;
183
183
184
- if ( psObject != null )
184
+ try
185
185
{
186
- childVariables . AddRange (
187
- psObject
188
- . Properties
189
- . Select ( p => new VariableDetails ( p ) ) ) ;
190
- }
191
- else if ( dictionary != null )
192
- {
193
- childVariables . AddRange (
194
- dictionary
195
- . OfType < DictionaryEntry > ( )
196
- . Select ( e => new VariableDetails ( e . Key . ToString ( ) , e . Value ) ) ) ;
197
- }
198
- else if ( enumerable != null && ! ( obj is string ) )
199
- {
200
- int i = 0 ;
201
- foreach ( var item in enumerable )
186
+ if ( psObject != null )
202
187
{
203
- childVariables . Add (
204
- new VariableDetails (
205
- string . Format ( "[{0}]" , i ) ,
206
- item ) ) ;
207
-
208
- i ++ ;
188
+ childVariables . AddRange (
189
+ psObject
190
+ . Properties
191
+ . Select ( p => new VariableDetails ( p ) ) ) ;
209
192
}
210
- }
211
- else if ( obj != null )
212
- {
213
- // Object must be a normal .NET type, pull all of its
214
- // properties and their values
215
- Type objectType = obj . GetType ( ) ;
216
- var properties =
217
- objectType . GetProperties (
218
- BindingFlags . Public | BindingFlags . Instance ) ;
219
-
220
- foreach ( var property in properties )
193
+ else if ( dictionary != null )
194
+ {
195
+ childVariables . AddRange (
196
+ dictionary
197
+ . OfType < DictionaryEntry > ( )
198
+ . Select ( e => new VariableDetails ( e . Key . ToString ( ) , e . Value ) ) ) ;
199
+ }
200
+ else if ( enumerable != null && ! ( obj is string ) )
221
201
{
222
- try
202
+ int i = 0 ;
203
+ foreach ( var item in enumerable )
223
204
{
224
205
childVariables . Add (
225
206
new VariableDetails (
226
- property . Name ,
227
- property . GetValue ( obj ) ) ) ;
207
+ string . Format ( "[{0}]" , i ) ,
208
+ item ) ) ;
209
+
210
+ i ++ ;
228
211
}
229
- catch ( Exception )
212
+ }
213
+ else if ( obj != null )
214
+ {
215
+ // Object must be a normal .NET type, pull all of its
216
+ // properties and their values
217
+ Type objectType = obj . GetType ( ) ;
218
+ var properties =
219
+ objectType . GetProperties (
220
+ BindingFlags . Public | BindingFlags . Instance ) ;
221
+
222
+ foreach ( var property in properties )
230
223
{
231
- // Some properties can throw exceptions, add the property
232
- // name and empty string
233
- childVariables . Add (
234
- new VariableDetails (
235
- property . Name ,
236
- string . Empty ) ) ;
224
+ try
225
+ {
226
+ childVariables . Add (
227
+ new VariableDetails (
228
+ property . Name ,
229
+ property . GetValue ( obj ) ) ) ;
230
+ }
231
+ catch ( Exception )
232
+ {
233
+ // Some properties can throw exceptions, add the property
234
+ // name and empty string
235
+ childVariables . Add (
236
+ new VariableDetails (
237
+ property . Name ,
238
+ string . Empty ) ) ;
239
+ }
237
240
}
238
241
}
239
242
}
243
+ catch ( GetValueInvocationException )
244
+ {
245
+ // This exception occurs when accessing the value of a
246
+ // variable causes a script to be executed. Right now
247
+ // we aren't loading children on the pipeline thread so
248
+ // this causes an exception to be raised. In this case,
249
+ // just return an empty list of children.
250
+ }
240
251
241
252
return childVariables . ToArray ( ) ;
242
253
}
0 commit comments