to get this to work use custom converter overriding the ReadJson, and WriteJson methods
public class CustomConverter : JsonConverter{
public override void WriteJson(JsonWriter writer,
object value,
JsonSerializer serializer)
{
if (value is DynamicSword)
{
var ds = (DynamicSword)value;
string[] serializable;
string[] notSerializable;
ds.SetSerializableAndNotSerializable(out serializable, out notSerializable);
var jobject = new JObject();
foreach (var item in serializable)
{
var tempValue = ds[item];
if (tempValue != null)
{
jobject.Add(item, JToken.FromObject(tempValue));
}
}
jobject.WriteTo(writer);
}
else
{
JToken t = JToken.FromObject(value);
t.WriteTo(writer);
}
}
public override bool CanConvert(Type objectType)
{
return true;
}
public override object ReadJson(JsonReader reader,
Type objectType,
object existingValue,
JsonSerializer serializer)
{
ConstructorInfo magicConstructor = objectType.GetConstructor(Type.EmptyTypes);
var newObject = magicConstructor.Invoke(new object[]{});
JObject jObject = JObject.Load(reader);
if (newObject is DynamicSword)
{
var ds = (DynamicSword)newObject;
hydrate(jObject, ds);
}
else
{
//do something different?
//really shoulnt be in here anyways
}
return newObject;
}
....
}