In a project(in C#) that I am working on I have to use a JSON representation that also contains methods of serialized object. That is the reason why I have to implement my own serializer. The Serializer is quite simply implemented with reflection. My problem is that it must also be able to handle objects with "self-creating" properties that are of the same type as original object.
Example:
class ClassA
{
private ClassA a;
public ClassA A
{
get
{
if (a == null)
a = new ClassA();
return a;
}
}
}
Everytime I iterate over Properties new object (a) is created, and this way the Serializer ends up in an infinite recursion.
Any idea how to avoid this? Any suggestions are appreciated.