The ObjectFiller is able to detect circulare references. You can configure the ObjectFiller to 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 and leave the property null.
In the following example the class "Parent
" has a List<Children>
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, ObjectFiller 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();
}
}