When I serialize an object using JsonConvert
using the following code:
JsonConvert.SerializeObject(new Foo())
The result is:
{"count":{"Value":3},"name":{"Value":"Tom"}}
I would like the result to look like this. So without the embedded { "Value": * }
structure.
{"count":3,"name":Tom}
I need use JObject.FromObject and JsonConvert.SerializeObject.
The code for the Foo class:
public class Foo
{
public DeltaProperty<int> count = new DeltaProperty<int>(3);
public DeltaProperty<string> name = new DeltaProperty<string>("Tom");
}
public class DeltaProperty<T>
{
public T Value
{
get
{
m_isDirty = false;
return m_value;
}
set
{
if (!m_value.Equals(value))
{
m_isDirty = true;
m_value = value;
}
}
}
private bool m_isDirty = default;
private T m_value = default;
public DeltaProperty(T val)
{
Value = val;
}
public bool ShouldSerializeValue()
{
return m_isDirty;
}
public override string ToString()
{
return m_value.ToString();
}
}