Class NullRecursionHandler

Namespace: AutoFixture.Kernel
Assembly: AutoFixture.dll

Breaks a recursion by returning null.

public class NullRecursionHandler : IRecursionHandler

Inheritance

objectNullRecursionHandler

Implements

IRecursionHandler

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Remarks

Some type designs contain circular references, for example in the form of parent/child relationships. Often the circular reference design involves a mutable property where a client can assign a parent to a child, or vice versa. Such a property may accept null as input, effectively breaking the circular reference. As an example, setting a Parent property to null may indicate that the instance represents a root node.

Constructors

NullRecursionHandler()

public NullRecursionHandler()

Methods

HandleRecursiveRequest(object, IEnumerable<object>)

Handles a recursive request by returning null.

public object HandleRecursiveRequest(object request, IEnumerable<object> recordedRequests)

Parameters

request object

The request causing the recursion.

recordedRequests IEnumerable<object>

Previously recorded, and yet unhandled, requests.

Returns

object

null.

Remarks

This method is called when AutoFixture detects an infinite recursion. The request is the request that triggered the recursion detection; recordedRequests contains all previous, but still unhandled requests: the current call stack, if you will.

This implementation breaks the recursion by returning null. This is not always the appropriate response, because the property or method argument requested may contain a Guard Clause preventing null from being accepted. However, if the member in question accepts null as valid input, returning null to break the recursion may be an appropriate response.

See Also

NullRecursionHandler

See Also

NullRecursionHandler.HandleRecursiveRequest(object, IEnumerable<object>)