public void SerializeObject(object target, IDataAdapter data, ISubSerializer subSerializer) { CustomSerializationClass obj = (CustomSerializationClass)target; data.AddStringValue(obj.A, "someData", true); data.AddStringValue(obj.B.ToString(), "someOtherData", true); }
private void SerializeValue(Type type, object value, IDataAdapter data, Info info, bool isReadOnly) { if (info.Category == TypeCategory.Primitive) { // no need to serialize if (isReadOnly) { return; } SerializePrimitive(type, value, data, info.Name, info.Location != NanoLocation.SubNode); return; } if (info.Category == TypeCategory.Enum) { // no need to serialize if (isReadOnly) { return; } if (settings.EnumsAsValue) { data.AddIntValue(((IConvertible)value).ToInt64(null), info.Name, info.Location != NanoLocation.SubNode); } else { data.AddStringValue(value.ToString(), info.Name, info.Location != NanoLocation.SubNode); } return; } if (info.Location == NanoLocation.Attribute) { throw new SerializationException($"Unable to serialize {type.Name} to attribute"); } IDataAdapter subNode = data.AddChild(info.Name); SerializeSubValue(type, value, subNode, info.GenericArgs); }
void INanoSerializable.Serialize(IDataAdapter data, ISubSerializer subSerializer) { data.AddStringValue(A, "1", true); subSerializer.ContinueSerialization(typeof(object), B, data.AddChild("1").AddChild("2")); }