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(), };
public static JToken ToJson(this StackItem item, string typeHint = "") { var stringRep = item.ToStringRep(typeHint); return(stringRep != null ? (JToken)stringRep : item switch { Neo.VM.Types.Boolean _ => item.GetBoolean(), // Neo.VM.Types.Buffer buffer => "Buffer", 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 _ => MakeVariable("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(), });