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
typeTypeThe CLR type to instantiate.
Returns
Exceptions
- ArgumentNullException
Thrown when
typeis null.
CreateInstance<T>()
Strongly-typed counterpart to CreateInstance(Type).
public static T CreateInstance<T>() where T : new()
Returns
- T
A freshly-constructed
Tinstance.
Type Parameters
TThe type to instantiate. Must have an accessible parameterless constructor.