Handle Circular Hierarchies
The ObjectFiller is able to detect circulare references. You can specify that the ObjectFiller will ignore the circular references or throw an exception when a circular reference occurs. By default ObjectFiller.NET stops creating new instances in a circular reference after one loop.
In the following example the class "Parent" has a List and the class Children has a again a Parent - this is called a circular reference. The ObjectFiller.NET detects that and doesn't fill the circular object anymore! When .Setup().OnCircularReference().ThrowException(true); with the true flag is called it will raise an exception instead of just ignore the circular reference.
public class Children
{
public Parent Parent { get; set; }
}
public class Parent
{
public List<Children> Childrens { get; set; }
}
public class HelloFiller
{
public void FillPerson()
{
Filler<Parent> pFiller = new Filler<Parent>();
pFiller.Setup()
.OnCircularReference().ThrowException(false);
Parent filledParent = pFiller.Create();
}
}
Updated less than a minute ago