Table of Contents

Class Initialization

Namespace
Garyon.Functions
Assembly
Garyon.dll

Provides useful functions for initializing variables, fields or properties.

public static class Initialization
Inheritance
Initialization
Inherited Members

Methods

TryInitializeUpcast<TDerived, TBase>(ref TDerived?, TBase)

Attempts to initialize a field of type TDerived, with a suitable TDerived value stored in a variable of TBase.

public static bool TryInitializeUpcast<TDerived, TBase>(ref TDerived? field, TBase value) where TDerived : class, TBase where TBase : class

Parameters

field TDerived

The field that will be initialized, if not already initialized. This means, if the field is not null, it will not be set.

value TBase

The value to attempt to set the field to, if its runtime type is at least TDerived.

Returns

bool

true if field was null at the time of calling this method, and the runtime type of value allows its value to be stored in field, otherwise false.

Type Parameters

TDerived

The type of the values stored in the field.

TBase

The base type, from which TDerived derives.

TrySetUpcast<TDerived, TBase>(ref TDerived?, TBase)

Attempts to set a field of type TDerived to a TDerived value stored in a variable of TBase.

public static bool TrySetUpcast<TDerived, TBase>(ref TDerived? field, TBase value) where TDerived : class, TBase where TBase : class

Parameters

field TDerived

The field that may be set to the given value.

value TBase

The value to attempt to set the field to, if its runtime type is at least TDerived.

Returns

bool

true if the runtime type of value allows its value to be stored in field, otherwise false.

Type Parameters

TDerived

The type of the values stored in the field.

TBase

The base type, from which TDerived derives.