Class IntPtrGuard
Guards against requests for System.IntPtr by throwing an exception.
Inheritance
Implements
Inherited Members
Namespace: AutoFixture.Kernel
Assembly: AutoFixture.dll
Syntax
public class IntPtrGuard : ISpecimenBuilder
Remarks
Some types (e.g. System.Func<TResult>) have constructors that take an System.IntPtr instance that indicate the address of the code block to be executed. IntPtr in itself have several constructors, amongst a few that AutoFixture thinks it can resolve; e.g. the constructor that takes an System.Int32 as input. This means that AutoFixture, unless prevented, will create IntPtr instances with completely invalid addresses such as 1 or 2. When code attempts to use these invalid IntPtr instances, the process crashes.
To prevent the process from crashing, AutoFixture considers request for IntPtr instances illegal. This class implements that rule by throwing an exception if such a request is detected.
Methods
| Improve this Doc View SourceCreate(Object, ISpecimenContext)
Guards against requests for System.IntPtr.
Declaration
public object Create(object request, ISpecimenContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Object | request | The request that describes what to create. |
ISpecimenContext | context | A context that can be used to create other specimens. |
Returns
Type | Description |
---|---|
System.Object | A NoSpecimen instance, unless |
Exceptions
Type | Condition |
---|---|
IllegalRequestException |
|