Table of Contents

Class TypeFactory

Namespace
ToSic.Sys.Utils
Assembly
ToSic.Sys.Utils.dll

Special helper to create objects from a type.

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public static class TypeFactory
Inheritance
object
TypeFactory

Remarks

The type must have a parameterless constructor, otherwise it will throw an error.

Methods

CreateInstance(Type)

public static object CreateInstance(Type type)

Parameters

type Type

Returns

object

CreateInstanceFunc(Type)

GetOrAdd ensures we only compile the expression once

public static Func<object> CreateInstanceFunc(Type type)

Parameters

type Type

Returns

Func<object>

Exceptions

InvalidOperationException

CreateInstance<T>()

The Generic Wrapper: Uses the central cache but returns the correct type.

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

Returns

T

Type Parameters

T