CVB.Net 14.0
ValueVariant< T1, T2 > Struct Template Reference

A variant stores one value of either type T1 or T2. More...

Inherits IStrongBox.

Public Member Functions

 ValueVariant (T1 value)
 Creates a new variant from the given value . More...
 
 ValueVariant (T2 value)
 Creates a new variant from the given value . More...
 
void Reset ()
 Resets the value. More...
 
T1 AsT1 ()
 Gets the value as T1. More...
 
void Assign (T1 value)
 Assigns the given value to this variant. More...
 
T2 AsT2 ()
 Gets the value as T2. More...
 
void Assign (T2 value)
 Assigns the given value to this variant. More...
 
ValueVariant< O1, O2 > ToVariant< O1, O2 > ()
 Translates this variant to another variant. More...
 

Static Public Member Functions

static implicit operator ValueVariant< T1, T2 > (T1 value)
 Implicitly creates a new variant from the given value . More...
 
static implicit operator T1 (ValueVariant< T1, T2 > value)
 Implicitly converts the variant value to its T1 value. More...
 
static implicit operator ValueVariant< T1, T2 > (T2 value)
 Implicitly creates a new variant from the given value . More...
 
static implicit operator T2 (ValueVariant< T1, T2 > value)
 Implicitly converts the variant value to its T1 value. More...
 

Properties

bool IsSet [get]
 Gets whether a value is set at all. More...
 
bool IsT1 [get]
 Gets whether a value of type T1 is set. More...
 
bool IsT2 [get]
 Gets whether a value of type T2 is set. More...
 

Detailed Description

A variant stores one value of either type T1 or T2.

Value access is type safe.

Template Parameters
T1First type to store.
T2Second type to store.

Constructor & Destructor Documentation

◆ ValueVariant() [1/2]

ValueVariant ( T1  value)

Creates a new variant from the given value .

Parameters
valueValue to store.

◆ ValueVariant() [2/2]

ValueVariant ( T2  value)

Creates a new variant from the given value .

Parameters
valueValue to store.

Member Function Documentation

◆ Assign() [1/2]

void Assign ( T1  value)

Assigns the given value to this variant.

Parameters
valueValue to set.

◆ Assign() [2/2]

void Assign ( T2  value)

Assigns the given value to this variant.

Parameters
valueValue to set.

◆ AsT1()

T1 AsT1 ( )

Gets the value as T1.

Returns
Value as T1.
Exceptions
InvalidCastExceptionThrown if value stored is not of type T1

◆ AsT2()

T2 AsT2 ( )

Gets the value as T2.

Returns
Value as T2.
Exceptions
InvalidCastExceptionThrown if value stored is not of type T2

◆ operator T1()

static implicit operator T1 ( ValueVariant< T1, T2 >  value)
static

Implicitly converts the variant value to its T1 value.

Parameters
value

◆ operator T2()

static implicit operator T2 ( ValueVariant< T1, T2 >  value)
static

Implicitly converts the variant value to its T1 value.

Parameters
value

◆ operator ValueVariant< T1, T2 >() [1/2]

static implicit operator ValueVariant< T1, T2 > ( T1  value)
static

Implicitly creates a new variant from the given value .

Parameters
valueValue to create variant from.

◆ operator ValueVariant< T1, T2 >() [2/2]

static implicit operator ValueVariant< T1, T2 > ( T2  value)
static

Implicitly creates a new variant from the given value .

Parameters
valueValue to create variant from.

◆ Reset()

void Reset ( )

Resets the value.

After this call IsSet returns false.

◆ ToVariant< O1, O2 >()

ValueVariant< O1, O2 > ToVariant< O1, O2 > ( )

Translates this variant to another variant.

Attention: use with care. The translations are not totally fool proof.

Template Parameters
O1First target type.
O2Second target type.
Returns

Property Documentation

◆ IsSet

bool IsSet
get

Gets whether a value is set at all.

true if a value is set.

◆ IsT1

bool IsT1
get

Gets whether a value of type T1 is set.

true if value is set and it is of type T1.

◆ IsT2

bool IsT2
get

Gets whether a value of type T2 is set.

true if value is set and it is of type T2.