Class IntPtrGuard

Namespace: AutoFixture.Kernel
Assembly: AutoFixture.dll

Guards against requests for IntPtr by throwing an exception.

public class IntPtrGuard : ISpecimenBuilder

Inheritance

objectIntPtrGuard

Implements

ISpecimenBuilder

Inherited Members

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

Extension Methods

SpecimenFactory.Create<T>(ISpecimenBuilder), SpecimenFactory.CreateMany<T>(ISpecimenBuilder), SpecimenFactory.CreateMany<T>(ISpecimenBuilder, int), SpecimenCommand.Do<T>(ISpecimenBuilder, Action<T>), SpecimenCommand.Do<T1, T2>(ISpecimenBuilder, Action<T1, T2>), SpecimenCommand.Do<T1, T2, T3>(ISpecimenBuilder, Action<T1, T2, T3>), SpecimenCommand.Do<T1, T2, T3, T4>(ISpecimenBuilder, Action<T1, T2, T3, T4>), SpecimenQuery.Get<T, TResult>(ISpecimenBuilder, Func<T, TResult>), SpecimenQuery.Get<T1, T2, TResult>(ISpecimenBuilder, Func<T1, T2, TResult>), SpecimenQuery.Get<T1, T2, T3, TResult>(ISpecimenBuilder, Func<T1, T2, T3, TResult>), SpecimenQuery.Get<T1, T2, T3, T4, TResult>(ISpecimenBuilder, Func<T1, T2, T3, T4, TResult>), CustomizationExtensions.ToCustomization(ISpecimenBuilder)

Remarks

Some types (e.g. `Func%601`) have constructors that take an `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 `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.

Constructors

IntPtrGuard()

public IntPtrGuard()

Methods

Create(object, ISpecimenContext)

Guards against requests for IntPtr.

public object Create(object request, ISpecimenContext context)

Parameters

request object

The request that describes what to create.

context ISpecimenContext

A context that can be used to create other specimens.

Returns

object

A NoSpecimen instance, unless request is a request for IntPtr in which case an exception is thrown.

Exceptions

IllegalRequestException

request is the IntPtr Type.