Example #1
0
        public IEnumerable <Variable> Enumerate(IVariableManager manager)
        {
            foreach (var key in map.Keys)
            {
                var keyString = key switch
                {
                    Neo.VM.Types.Boolean @bool => @bool.GetBoolean().ToString(),
                         Neo.VM.Types.ByteString byteString => byteString.GetSpan().ToHexString(),
                         Neo.VM.Types.Integer @int => @int.GetInteger().ToString(),
                         _ => throw new NotImplementedException($"Unknown primitive type {key.GetType()}"),
                };

                yield return(map[key].ToVariable(manager, keyString));
            }
        }
Example #2
0
        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(),
            });