Table of Contents

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

T1

The first type.

T2

The second type.

Implements
IMixed<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

value T1

The item, or the default value of the type.

Returns

bool

true if the item is of this type.

Is(out T2)

Gets the item if it is of the second type.

public bool Is(out T2 value)

Parameters

value T2

The item, or the default value of the type.

Returns

bool

true if the item is of this type.

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

first Action<T1>

What to do with an item of the first type.

second Action<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

first Func<T1, TResult>

What to do with an item of the first type.

second Func<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

TResult

The type of the result.

Exceptions

ArgumentNullException

A function is null.

InvalidOperationException

This is the default value, which holds nothing.