PS ConvertFrom-Json replaced with JSONParser

This commit is contained in:
Frank Skare
2021-09-03 13:04:06 +02:00
parent 33fb645694
commit 0d72731ce7
4 changed files with 49 additions and 44 deletions

View File

@@ -9,6 +9,7 @@ using System.Windows;
using static mpvnet.Global;
using System.Collections.Generic;
using System.Text;
namespace mpvnet
{
@@ -290,27 +291,27 @@ namespace mpvnet
public static void ShowCommands()
{
string code = @"
foreach ($item in ($json | ConvertFrom-Json | foreach { $_ } | sort name))
{
''
$item.name
foreach ($arg in $item.args)
{
$value = $arg.name + ' <' + $arg.type.ToLower() + '>'
if ($arg.optional -eq $true)
{
$value = '[' + $value + ']'
}
' ' + $value
}
}";
string json = Core.GetPropertyString("command-list");
ShowTextWithEditor("command-list", PowerShell.InvokeAndReturnString(code, "json", json));
var o = json.FromJson<List<Dictionary<string, object>>>().OrderBy(i => i["name"]);
StringBuilder sb = new StringBuilder();
foreach (Dictionary<string, object> i in o)
{
sb.AppendLine();
sb.AppendLine(i["name"].ToString());
foreach (Dictionary<string, object> i2 in i["args"] as List<object>)
{
string value = i2["name"].ToString() + " <" + i2["type"].ToString().ToLower() + ">";
if ((bool)i2["optional"] == true)
value = "[" + value + "]";
sb.AppendLine(" " + value);
}
}
ShowTextWithEditor("command-list", sb.ToString());
}
public static void ShowTextWithEditor(string name, string text)