Class InstanceFunction
Stores a late-bound factory delegate that can create an instance of a specific runtime type.
Inherited Members
Namespace: FastMoq.Models
Assembly: FastMoq.Core.dll
Syntax
public class InstanceFunction
Constructors
InstanceFunction(Type)
Stores a late-bound factory delegate that can create an instance of a specific runtime type.
Declaration
public InstanceFunction(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The runtime type produced by the stored factory delegate. |
Properties
Function
Gets or sets the factory delegate used to create the instance.
Declaration
public Delegate? Function { get; set; }
Property Value
| Type | Description |
|---|---|
| Delegate |
InstanceType
Gets the runtime type that this factory produces.
Declaration
public Type InstanceType { get; }
Property Value
| Type | Description |
|---|---|
| Type |
Methods
CreateInstance(Type)
Creates a new InstanceFunction placeholder for the specified runtime type.
Declaration
public static InstanceFunction CreateInstance(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The runtime type the instance function should describe. |
Returns
| Type | Description |
|---|---|
| InstanceFunction | A new InstanceFunction for |
Invoke(Mocker, params object?[]?)
Invokes the stored factory delegate with the supplied Mocker and optional parameter values.
Declaration
public object? Invoke(Mocker mocker, params object?[]? parameters)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The active mocker used as the first delegate argument. |
| object[] | parameters | Optional extra parameters passed to delegates that accept a second argument. |
Returns
| Type | Description |
|---|---|
| object | The created instance, or null when the stored delegate returns null. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when no compatible delegate has been assigned. |
SetFunction(Delegate)
Assigns the factory delegate used to create the instance.
Declaration
public void SetFunction(Delegate function)
Parameters
| Type | Name | Description |
|---|---|---|
| Delegate | function | The delegate to store for later invocation. |