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
typeTypeThe 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
typeTypeThe type to instantiate.
Returns
- T
A new instance cast to T, or null if creation fails.
Type Parameters
TThe 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
typeTypeThe type to instantiate.