Skip to content

Hotfix for bug in Set-AzureResource #442

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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