Skip to content

Integrate from release to master as a part of Release 0.9.3 #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 6, 2015
Prev Previous commit
Next Next commit
Update PsObjectExtensions.cs
Fixes serialization bug
  • Loading branch information
chadiel committed May 29, 2015
commit 2f0f889c4c269da6d8d3d6f2198d1c927ae3dcb3
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,36 @@ private static JToken ToJToken(object value)
return obj;
}

var valueAsArray = value as Array;
if (valueAsArray != null)
var valueAsDictionary = value as IDictionary;
if (valueAsDictionary != null)
{
var retVal = new JToken[valueAsArray.Length];
for (int i = 0; i < valueAsArray.Length; ++i)
JObject obj = new JObject();
var dictionaryEntries = valueAsDictionary is IDictionary<string, object>
? valueAsDictionary.OfType<KeyValuePair<string, object>>().Select(kvp => Tuple.Create(kvp.Key, kvp.Value))
: valueAsDictionary.OfType<DictionaryEntry>().Select(dictionaryEntry => Tuple.Create(dictionaryEntry.Key.ToString(), dictionaryEntry.Value));

dictionaryEntries = dictionaryEntries.Any(dictionaryEntry => dictionaryEntry.Item1.EqualsInsensitively(Constants.MicrosoftAzureResource))
? dictionaryEntries.Where(dictionaryEntry => !PsObjectExtensions.PropertiesToRemove.ContainsKey(dictionaryEntry.Item1))
: dictionaryEntries;

foreach (var dictionaryEntry in dictionaryEntries)
{
obj.Add(dictionaryEntry.Item1, PsObjectExtensions.ToJToken(dictionaryEntry.Item2));
}

return obj;
}

var valueAsIList = value as IList;
if (valueAsIList != null)
{
var tmpList = new List<JToken>();
foreach(var v in valueAsIList)
{
retVal[i] = PsObjectExtensions.ToJToken(valueAsArray.GetValue(i));
tmpList.Add(PsObjectExtensions.ToJToken(v));
}

return JArray.FromObject(retVal);
return JArray.FromObject(tmpList.ToArray());
}

return new JValue(value.ToString());
Expand Down