@@ -99,16 +99,36 @@ private static JToken ToJToken(object value)
99
99
return obj ;
100
100
}
101
101
102
- var valueAsArray = value as Array ;
103
- if ( valueAsArray != null )
102
+ var valueAsDictionary = value as IDictionary ;
103
+ if ( valueAsDictionary != null )
104
104
{
105
- var retVal = new JToken [ valueAsArray . Length ] ;
106
- for ( int i = 0 ; i < valueAsArray . Length ; ++ i )
105
+ JObject obj = new JObject ( ) ;
106
+ var dictionaryEntries = valueAsDictionary is IDictionary < string , object >
107
+ ? valueAsDictionary . OfType < KeyValuePair < string , object > > ( ) . Select ( kvp => Tuple . Create ( kvp . Key , kvp . Value ) )
108
+ : valueAsDictionary . OfType < DictionaryEntry > ( ) . Select ( dictionaryEntry => Tuple . Create ( dictionaryEntry . Key . ToString ( ) , dictionaryEntry . Value ) ) ;
109
+
110
+ dictionaryEntries = dictionaryEntries . Any ( dictionaryEntry => dictionaryEntry . Item1 . EqualsInsensitively ( Constants . MicrosoftAzureResource ) )
111
+ ? dictionaryEntries . Where ( dictionaryEntry => ! PsObjectExtensions . PropertiesToRemove . ContainsKey ( dictionaryEntry . Item1 ) )
112
+ : dictionaryEntries ;
113
+
114
+ foreach ( var dictionaryEntry in dictionaryEntries )
115
+ {
116
+ obj . Add ( dictionaryEntry . Item1 , PsObjectExtensions . ToJToken ( dictionaryEntry . Item2 ) ) ;
117
+ }
118
+
119
+ return obj ;
120
+ }
121
+
122
+ var valueAsIList = value as IList ;
123
+ if ( valueAsIList != null )
124
+ {
125
+ var tmpList = new List < JToken > ( ) ;
126
+ foreach ( var v in valueAsIList )
107
127
{
108
- retVal [ i ] = PsObjectExtensions . ToJToken ( valueAsArray . GetValue ( i ) ) ;
128
+ tmpList . Add ( PsObjectExtensions . ToJToken ( v ) ) ;
109
129
}
110
130
111
- return JArray . FromObject ( retVal ) ;
131
+ return JArray . FromObject ( tmpList . ToArray ( ) ) ;
112
132
}
113
133
114
134
return new JValue ( value . ToString ( ) ) ;
0 commit comments