Table of Contents

Class DefaultInstanceContainer<TBase>

Namespace
Garyon.Reflection
Assembly
Garyon.dll

Provides a mechanism to initialize default instances of a type, including deriving types.

public abstract class DefaultInstanceContainer<TBase> where TBase : class

Type Parameters

TBase

The base type whose default instances to initialize.

Inheritance
DefaultInstanceContainer<TBase>
Inherited Members
Extension Methods

Constructors

DefaultInstanceContainer()

Initializes a new DefaultInstanceContainer<TBase> instance with all the types available from Current, filtered through IsValidInstanceType(Type).

protected DefaultInstanceContainer()

Remarks

All types that are considered valid must contain a constructor matching the argument types as returned from GetDefaultInstanceArgumentTypes().

Properties

DefaultInstanceTypes

Gets all the default instance types that were found in all the assemblies this program can refer to.

public ImmutableArray<Type> DefaultInstanceTypes { get; }

Property Value

ImmutableArray<Type>

Methods

GetDefaultInstance(string)

Gets the default initialized instance of the type bearing the given type name.

public TBase? GetDefaultInstance(string typeName)

Parameters

typeName string

The name of the type whose default initialized instance to get.

Returns

TBase

The default initialized instance of the type, if it is initialized, otherwise null.

GetDefaultInstance(Type?)

Gets the default initialized instance of the given type.

public TBase? GetDefaultInstance(Type? type)

Parameters

type Type

The type whose default initialized instance to get.

Returns

TBase

The default initialized instance of the type, if it is initialized, otherwise null.

GetDefaultInstanceArgumentTypes()

Gets the argument types to be used in the constructor for each of the valid types to initialize the default instance from.

protected virtual Type[] GetDefaultInstanceArgumentTypes()

Returns

Type[]

Remarks

Defaults to returning the types of the arguments as provided from GetDefaultInstanceArguments(). For null objects, the object type is used.

GetDefaultInstanceArguments()

Gets the arguments to be used in the constructor.

protected abstract object?[] GetDefaultInstanceArguments()

Returns

object[]

GetDefaultInstance<TInstance>()

Gets the default initialized instance of the given type.

public TBase? GetDefaultInstance<TInstance>() where TInstance : TBase

Returns

TBase

The default initialized instance of the type, if it is initialized, otherwise null.

Type Parameters

TInstance

The type whose default initialized instance to get.

IsValidInstanceType(Type)

Determines whether the given type can be considered a valid instance type.

protected virtual bool IsValidInstanceType(Type type)

Parameters

type Type

The instance type to determine whether it is considered valid. The type will never be abstract, and will always be assignable to TBase instances.

Returns

bool

true if the type's default instance should be stored, otherwise false.

Remarks

Defaults to always returning true. This can be a common implementation for unconstrained types whose default instances to initialize.