Struct MixedChange<T1, T2, T3, T4>
One change of a typed read of several entities: a Change<T> of one of the types, from shop.ReadChangesAsync<Customer, Order>(streams, ...). Ask with
change.Is(out Change<Customer>? customer), or handle every case with Match, which is what stays correct when a type is added.
public readonly struct MixedChange<T1, T2, T3, T4> where T1 : IDynamoDbDiscriminated<T1> where T2 : IDynamoDbDiscriminated<T2> where T3 : IDynamoDbDiscriminated<T3> where T4 : IDynamoDbDiscriminated<T4>
Type Parameters
T1The first type.
T2The second type.
T3The third type.
T4The fourth type.
- Inherited Members
Remarks
It is to Change<T> what Mixed<T1, T2, T3, T4> of a mixed read is to an entity, with the same members. That one is a document, which a read fills and From<T>(T) writes;
this one holds a change, which is neither. The default value holds nothing,
and Match throws on it; a typed read never gives one. A test builds one with the constructor of its type.
Constructors
MixedChange(Change<T1>)
Initializes a new instance of the MixedChange<T1, T2, T3, T4> struct that holds a change of the first type, as a typed read gives it, so that a test of code that
handles the changes of a reading builds its input: new MixedChange<Customer, Order, Invoice, Payment>(new Change<Customer> { Kind = OperationType.Insert, After = customer, Record = new ChangeRecord() }).
public MixedChange(Change<T1> change)
Parameters
changeChange<T1>The change.
Remarks
There is one constructor per type, and the type of the argument picks it. Two equal types make the call ambiguous, which does not compile, and a reading of them could not tell them apart either: it throws ArgumentException.
Exceptions
- ArgumentNullException
changeis null.
MixedChange(Change<T2>)
Initializes a new instance of the MixedChange<T1, T2, T3, T4> struct that holds a change of the second type, as a typed read gives it, so that a test of code that
handles the changes of a reading builds its input: new MixedChange<Customer, Order, Invoice, Payment>(new Change<Order> { Kind = OperationType.Insert, After = order, Record = new ChangeRecord() }).
public MixedChange(Change<T2> change)
Parameters
changeChange<T2>The change.
Remarks
There is one constructor per type, and the type of the argument picks it. Two equal types make the call ambiguous, which does not compile, and a reading of them could not tell them apart either: it throws ArgumentException.
Exceptions
- ArgumentNullException
changeis null.
MixedChange(Change<T3>)
Initializes a new instance of the MixedChange<T1, T2, T3, T4> struct that holds a change of the third type, as a typed read gives it, so that a test of code that
handles the changes of a reading builds its input: new MixedChange<Customer, Order, Invoice, Payment>(new Change<Invoice> { Kind = OperationType.Insert, After = invoice, Record = new ChangeRecord() }).
public MixedChange(Change<T3> change)
Parameters
changeChange<T3>The change.
Remarks
There is one constructor per type, and the type of the argument picks it. Two equal types make the call ambiguous, which does not compile, and a reading of them could not tell them apart either: it throws ArgumentException.
Exceptions
- ArgumentNullException
changeis null.
MixedChange(Change<T4>)
Initializes a new instance of the MixedChange<T1, T2, T3, T4> struct that holds a change of the fourth type, as a typed read gives it, so that a test of code that
handles the changes of a reading builds its input: new MixedChange<Customer, Order, Invoice, Payment>(new Change<Payment> { Kind = OperationType.Insert, After = payment, Record = new ChangeRecord() }).
public MixedChange(Change<T4> change)
Parameters
changeChange<T4>The change.
Remarks
There is one constructor per type, and the type of the argument picks it. Two equal types make the call ambiguous, which does not compile, and a reading of them could not tell them apart either: it throws ArgumentException.
Exceptions
- ArgumentNullException
changeis null.
Methods
Is(out Change<T1>?)
Gets the change if it is of the first type.
public bool Is(out Change<T1>? change)
Parameters
Returns
Is(out Change<T2>?)
Gets the change if it is of the second type.
public bool Is(out Change<T2>? change)
Parameters
Returns
Is(out Change<T3>?)
Gets the change if it is of the third type.
public bool Is(out Change<T3>? change)
Parameters
Returns
Is(out Change<T4>?)
Gets the change if it is of the fourth type.
public bool Is(out Change<T4>? change)
Parameters
Returns
Match(Action<Change<T1>>, Action<Change<T2>>, Action<Change<T3>>, Action<Change<T4>>)
Does something with the change, with one action per type, so no type can be forgotten.
public void Match(Action<Change<T1>> first, Action<Change<T2>> second, Action<Change<T3>> third, Action<Change<T4>> fourth)
Parameters
firstAction<Change<T1>>What to do with a change of the first type.
secondAction<Change<T2>>What to do with a change of the second type.
thirdAction<Change<T3>>What to do with a change of the third type.
fourthAction<Change<T4>>What to do with a change of the fourth type.
Exceptions
- ArgumentNullException
An action is null.
- InvalidOperationException
This is the default value, which holds nothing.
Match<TResult>(Func<Change<T1>, TResult>, Func<Change<T2>, TResult>, Func<Change<T3>, TResult>, Func<Change<T4>, TResult>)
Computes a result from the change, with one function per type, so no type can be forgotten.
public TResult Match<TResult>(Func<Change<T1>, TResult> first, Func<Change<T2>, TResult> second, Func<Change<T3>, TResult> third, Func<Change<T4>, TResult> fourth)
Parameters
firstFunc<Change<T1>, TResult>What to do with a change of the first type.
secondFunc<Change<T2>, TResult>What to do with a change of the second type.
thirdFunc<Change<T3>, TResult>What to do with a change of the third type.
fourthFunc<Change<T4>, TResult>What to do with a change of the fourth type.
Returns
- TResult
The result of the function of the type of the change.
Type Parameters
TResultThe type of the result.
Exceptions
- ArgumentNullException
A function is null.
- InvalidOperationException
This is the default value, which holds nothing.