Struct Mixed<T1, T2>
- Namespace
- DynaSharp
- Assembly
- DynaSharp.dll
One item of a mixed read: an item of one of several types, from shop.Query(pk).Of<Customer, Order>(). Ask with item.Is(out Customer customer), or
handle every case with Match<TResult>(Func<T1, TResult>, Func<T2, TResult>), which is what stays correct when a type is added.
public readonly struct Mixed<T1, T2> : IMixed<Mixed<T1, T2>>, IDynamoDbDocument<Mixed<T1, T2>> where T1 : IDynamoDbDiscriminated<T1> where T2 : IDynamoDbDiscriminated<T2>
Type Parameters
T1The first type.
T2The second type.
- Implements
-
IDynamoDbDocument<Mixed<T1, T2>>
- Inherited Members
Remarks
The default value holds nothing, and Match<TResult>(Func<T1, TResult>, Func<T2, TResult>) throws on it; a mixed read never gives one. As a document it writes the attributes of the item it holds, so From<T>(T) works on it.
Methods
Is(out T1)
Gets the item if it is of the first type.
public bool Is(out T1 value)
Parameters
valueT1The item, or the default value of the type.
Returns
Is(out T2)
Gets the item if it is of the second type.
public bool Is(out T2 value)
Parameters
valueT2The item, or the default value of the type.
Returns
Match(Action<T1>, Action<T2>)
Does something with the item, with one action per type, so no type can be forgotten.
public void Match(Action<T1> first, Action<T2> second)
Parameters
firstAction<T1>What to do with an item of the first type.
secondAction<T2>What to do with an item of the second type.
Exceptions
- ArgumentNullException
An action is null.
- InvalidOperationException
This is the default value, which holds nothing.
Match<TResult>(Func<T1, TResult>, Func<T2, TResult>)
Computes a result from the item, with one function per type, so no type can be forgotten.
public TResult Match<TResult>(Func<T1, TResult> first, Func<T2, TResult> second)
Parameters
firstFunc<T1, TResult>What to do with an item of the first type.
secondFunc<T2, TResult>What to do with an item of the second type.
Returns
- TResult
The result of the function of the type of the item.
Type Parameters
TResultThe type of the result.
Exceptions
- ArgumentNullException
A function is null.
- InvalidOperationException
This is the default value, which holds nothing.