greflect

package
v0.9.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapt

func Adapt[T any](src any) (T, error)

Adapt 将源对象 src 复制到目标类型 T 的新实例中,并返回该实例和可能发生的错误。 参数:

src - 源对象

返回值:

T - 目标类型 T 的新实例
error - 复制过程中可能发生的错误

func CanCallIsNil

func CanCallIsNil(v interface{}) bool

CanCallIsNil Can reflect.Value call reflect.Value.IsNil. It can avoid reflect.Value.IsNil panics.

func Instance

func Instance[T any]() T

Instance 创建一个指定类型 T 的零值实例。 参数:

T - 目标类型

返回值:

T - 指定类型 T 的零值实例

func InstanceOf

func InstanceOf(resultType reflect.Type) any

InstanceOf 根据给定的 reflect.Type 创建一个实例。 参数:

resultType - 反射类型

返回值:

any - 根据 resultType 创建的实例

func MustAdapt

func MustAdapt[T any](src any) T

MustAdapt 将源对象 src 复制到目标类型 T 的新实例中,忽略可能发生的错误。 参数:

src - 源对象

返回值:

T - 目标类型 T 的新实例

func NilOrEmpty

func NilOrEmpty[T any]() T

NilOrEmpty 创建一个指定类型 T 的零值实例。 参数:

T - 目标类型

返回值:

T - 指定类型 T 的零值实例

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL