Prototype complete InterpreterEntry serialization

This commit is contained in:
Yoshi Askharoun
2023-05-24 10:14:07 -05:00
parent 141a2200dd
commit bcf9b83f54
6 changed files with 117 additions and 62 deletions
@@ -1,11 +1,15 @@
using System;
using Microsoft.Iris.Markup;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
namespace Microsoft.Iris.Debug.Data;
[Serializable]
public class InterpreterEntry
{
public InterpreterEntry(object opCode, params OpCodeArgument[] args)
public InterpreterEntry(OpCode opCode, params OpCodeArgument[] args)
{
OpCode = opCode;
@@ -15,22 +19,25 @@ public class InterpreterEntry
Arguments = new List<OpCodeArgument>();
}
public object OpCode { get; }
public OpCode OpCode { get; }
public IList<OpCodeArgument> Arguments { get; }
public IList<object> ReturnValues { get; } = new List<object>();
public override string ToString()
{
return $"{OpCode}({string.Join(", ", Arguments)}) -> [{ReturnValues}]";
return $"{OpCode}({string.Join(", ", Arguments)}) -> [{string.Join(", ", ReturnValues)}]";
}
}
public class OpCodeArgument
[Serializable]
public class OpCodeArgument : ISerializable
{
public string Name { get; set; }
public Type Type { get; set; }
public object Value { get; set; }
protected bool CanSerializeValue => Value is ISerializable;
public OpCodeArgument(string name, Type type, object value)
{
Name = name;
@@ -38,5 +45,23 @@ public class OpCodeArgument
Value = value;
}
protected OpCodeArgument(SerializationInfo info, StreamingContext context)
{
Name = info.GetString(nameof(Name));
Type = Type.GetType(info.GetString(nameof(Type)), false);
bool canSerializeValue = info.GetBoolean(nameof(CanSerializeValue));
Type valueSerializeType = canSerializeValue ? Type : typeof(string);
Value = info.GetValue(nameof(Value), valueSerializeType);
}
public override string ToString() => $"{Type} {Value}";
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(nameof(Name), Name);
info.AddValue(nameof(Type), Type.FullName);
info.AddValue(nameof(CanSerializeValue), CanSerializeValue);
info.AddValue(nameof(Value), CanSerializeValue ? Value : Value.ToString());
}
}