Skip to content

Commit f9af7ca

Browse files
committed
VM: Yet more fixes for structs within structs serialization
1 parent c77c824 commit f9af7ca

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Phantasma.VM/VMObject.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,16 @@ public T AsStruct<T>()
384384

385385
Throw.If(fi == null, "unknown field: " + fieldName);
386386

387-
var fieldValue = entry.Value.ToObject();
387+
object fieldValue;
388+
389+
if (entry.Value.Type == VMType.Struct)
390+
{
391+
fieldValue = entry.Value.ToStruct(fi.FieldType);
392+
}
393+
else
394+
{
395+
fieldValue = entry.Value.ToObject();
396+
}
388397

389398
fieldValue = ConvertObjectInternal(fieldValue, fi.FieldType);
390399

@@ -1008,7 +1017,8 @@ public object ToObject()
10081017
case VMType.Timestamp: return this.AsTimestamp();
10091018
case VMType.Object: return this.Data;
10101019
case VMType.Enum: return this.Data;
1011-
default: return null;
1020+
1021+
default: throw new Exception($"Cannot cast {Type} to object");
10121022
}
10131023
}
10141024

0 commit comments

Comments
 (0)