Skip to main content
Table of Contents

Class ObjectFactory

Namespace
Stratara.Shared.Reflections
Assembly
Stratara.Shared.dll

Parameterless-constructor instantiation cache. Compiles a new T() lambda per requested type and reuses it for subsequent calls, avoiding the cost of repeated reflection / activation.

public static class ObjectFactory
Inheritance
ObjectFactory
Inherited Members

Remarks

The factory cache is unbounded and lives for the lifetime of the process; assumes a finite set of types per host.

Methods

CreateInstance(Type)

Creates a new instance of type using its parameterless constructor.

public static object CreateInstance(Type type)

Parameters

type Type

The CLR type to instantiate.

Returns

object

A freshly-constructed instance, boxed as object.

Exceptions

ArgumentNullException

Thrown when type is null.

CreateInstance<T>()

Strongly-typed counterpart to CreateInstance(Type).

public static T CreateInstance<T>() where T : new()

Returns

T

A freshly-constructed T instance.

Type Parameters

T

The type to instantiate. Must have an accessible parameterless constructor.