Table of Contents

Class TypeExtensions

Namespace
FishMMO.Shared
Assembly
FishMMO-SharedUtility.dll

Extension methods for System.Type, providing high-performance instance creation via compiled expression trees and thread-safe delegate caching.

public static class TypeExtensions
Inheritance
TypeExtensions
Inherited Members

Methods

CreateInstance(Type?)

Creates an instance of the specified type.

public static object? CreateInstance(this Type? type)

Parameters

type Type

The type to instantiate.

Returns

object

A new instance of the type.

CreateInstance<T>(Type?)

Creates an instance of the specified type and casts it to T.

public static T? CreateInstance<T>(this Type? type) where T : class

Parameters

type Type

The type to instantiate.

Returns

T

A new instance cast to T, or null if creation fails.

Type Parameters

T

The type to cast the instance to.

GetDefaultConstructorDelegate(Type?)

Gets or creates a compiled delegate for the parameterless constructor of the specified type.

public static Func<object?>? GetDefaultConstructorDelegate(this Type? type)

Parameters

type Type

The type to instantiate.

Returns

Func<object>

A delegate that creates an instance, or null if the type cannot be instantiated.