Class Initialization
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
fieldTDerivedThe field that will be initialized, if not already initialized. This means, if the field is not null, it will not be set.
valueTBaseThe value to attempt to set the field to, if its runtime type is at least
TDerived.
Returns
- bool
true if
fieldwas null at the time of calling this method, and the runtime type ofvalueallows its value to be stored infield, otherwise false.
Type Parameters
TDerivedThe type of the values stored in the field.
TBaseThe base type, from which
TDerivedderives.
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
fieldTDerivedThe field that may be set to the given value.
valueTBaseThe value to attempt to set the field to, if its runtime type is at least
TDerived.
Returns
Type Parameters
TDerivedThe type of the values stored in the field.
TBaseThe base type, from which
TDerivedderives.