Class NullRecursionHandler
Breaks a recursion by returning null.
Inheritance
Implements
Inherited Members
Namespace: AutoFixture.Kernel
Assembly: AutoFixture.dll
Syntax
public class NullRecursionHandler : IRecursionHandler
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.
Methods
| Improve this Doc View SourceHandleRecursiveRequest(Object, IEnumerable<Object>)
Handles a recursive request by returning null.
Declaration
public object HandleRecursiveRequest(object request, IEnumerable<object> recordedRequests)
Parameters
Type | Name | Description |
---|---|---|
System.Object | request | The request causing the recursion. |
System.Collections.Generic.IEnumerable<System.Object> | recordedRequests | Previously recorded, and yet unhandled, requests. |
Returns
Type | Description |
---|---|
System.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.