I'm implementing some custom serialization (to byte array), and have run into a problem handling circular references.
Example:
Class A
public MyBs as new List(of B)
end class
class B
public MyParent as A
public MiscInt1 as integer
public MiscInt2 as integer
end class
When serializing A, I must serialize each instance of B.
However, I have a problem when serializing B.
How do I record the parent of B without causing an infinite loop?
An idea:
If I know that an instance of B will only ever be serialized through the serialization of an instance of A, then I can handle the setup of the MyParent reference from the instance of A and not even record that information inside the byte buffer for the instance of B
This doesn't feel quite right, but it might be the best solution.
Is there a cleaner way of handling this situation?