Class BindingCommand<T, TProperty>

Namespace: AutoFixture.Kernel
Assembly: AutoFixture.dll

Encapsulates a command that binds a property or a field to a value.

public class BindingCommand<T, TProperty> : ISpecimenCommand

Type Parameters

T

The type of the specimen on which the property or value will be set.

TProperty

The type of property or field.

Inheritance

objectBindingCommand<T, TProperty>

Implements

ISpecimenCommand

Inherited Members

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

Constructors

BindingCommand(Expression<Func<T, TProperty>>)

Initializes a new instance of the BindingCommand%602 class with the supplied property picker expression.

public BindingCommand(Expression<Func<T, TProperty>> propertyPicker)

Parameters

propertyPicker Expression<Func<T, TProperty>>

An expression that identifies a property or field.

Remarks

This constructor implies that an anonymous value will be assigned to the property or field identified by propertyPicker.

BindingCommand(Expression<Func<T, TProperty>>, TProperty)

Initializes a new instance of the BindingCommand%602 class with the supplied property picker expression and the value to be assigned to that property or field.

public BindingCommand(Expression<Func<T, TProperty>> propertyPicker, TProperty propertyValue)

Parameters

propertyPicker Expression<Func<T, TProperty>>

An expression that identifies a property or field.

propertyValue TProperty

The value to assign to the property or field identified by propertyPicker.

BindingCommand(Expression<Func<T, TProperty>>, Func<ISpecimenContext, TProperty>)

Initializes a new instance of the BindingCommand%602 class with the supplied property picker expression and a function that creates a value to be assigned to that property or field.

public BindingCommand(Expression<Func<T, TProperty>> propertyPicker, Func<ISpecimenContext, TProperty> valueCreator)

Parameters

propertyPicker Expression<Func<T, TProperty>>

An expression that identifies a property or field.

valueCreator Func<ISpecimenContext, TProperty>

A function that creates a value that will be assigned to the property or field identified by propertyPicker.

Properties

Member

Gets the member identified by the expression supplied through the constructor.

public MemberInfo Member { get; }

Property Value

MemberInfo

ValueCreator

Gets the function that creates a value to be assigned to the property or field identified by Member.

public Func<ISpecimenContext, TProperty> ValueCreator { get; }

Property Value

Func<ISpecimenContext, TProperty>

Methods

Execute(object, ISpecimenContext)

Executes the command on the supplied specimen by assigning the property of field the correct value.

public void Execute(object specimen, ISpecimenContext context)

Parameters

specimen object

context ISpecimenContext

Remarks

This method assigns a value to the property or field identified by the expression supplied to the class' constructor. If no value (or creator) was supplied to the constructor, context will be used to create the value.