コード例 #1
0
 public static JToken ToJson(this StackItem item)
 {
     return item switch
     {
         Neo.VM.Types.Boolean _ => item.GetBoolean(),
         Neo.VM.Types.Buffer buffer => buffer.GetSpan().ToHexString(),
         Neo.VM.Types.ByteString byteString => byteString.GetSpan().ToHexString(),
         Neo.VM.Types.Integer @int => @int.GetInteger().ToString(),
         // Neo.VM.Types.InteropInterface _ => MakeVariable("InteropInterface"),
         Neo.VM.Types.Map map => MapToJson(map),
         Neo.VM.Types.Null _ => new JValue((object?)null),
         // Neo.VM.Types.Pointer _ => MakeVariable("Pointer"),
         Neo.VM.Types.Array array => new JArray(array.Select(i => i.ToJson())),
         _ => throw new NotSupportedException(),
     };
コード例 #2
0
            static async Task WriteStackItemAsync(System.IO.TextWriter writer, Neo.VM.Types.StackItem item, int indent = 1, string prefix = "")
            {
                switch (item)
                {
                case Neo.VM.Types.Boolean _:
                    await WriteLineAsync(item.GetBoolean()? "true" : "false").ConfigureAwait(false);

                    break;

                case Neo.VM.Types.Integer @int:
                    await WriteLineAsync(@int.GetInteger().ToString()).ConfigureAwait(false);

                    break;

                case Neo.VM.Types.Buffer buffer:
                    await WriteLineAsync(Neo.Helper.ToHexString(buffer.GetSpan())).ConfigureAwait(false);

                    break;

                case Neo.VM.Types.ByteString byteString:
                    await WriteLineAsync(Neo.Helper.ToHexString(byteString.GetSpan())).ConfigureAwait(false);

                    break;

                case Neo.VM.Types.Null _:
                    await WriteLineAsync("<null>").ConfigureAwait(false);

                    break;

                case Neo.VM.Types.Array array:
                    await WriteLineAsync($"Array: ({array.Count})").ConfigureAwait(false);

                    for (int i = 0; i < array.Count; i++)
                    {
                        await WriteStackItemAsync(writer, array[i], indent + 1).ConfigureAwait(false);
                    }
                    break;

                case Neo.VM.Types.Map map:
                    await WriteLineAsync($"Map: ({map.Count})").ConfigureAwait(false);

                    foreach (var m in map)
                    {
                        await WriteStackItemAsync(writer, m.Key, indent + 1, "key:   ").ConfigureAwait(false);
                        await WriteStackItemAsync(writer, m.Value, indent + 1, "value: ").ConfigureAwait(false);
                    }
                    break;
                }

                async Task WriteLineAsync(string value)
                {
                    for (var i = 0; i < indent; i++)
                    {
                        await writer.WriteAsync("  ").ConfigureAwait(false);
                    }

                    if (!string.IsNullOrEmpty(prefix))
                    {
                        await writer.WriteAsync(prefix).ConfigureAwait(false);
                    }

                    await writer.WriteLineAsync(value).ConfigureAwait(false);
                }
            }