reflectx

package module
v0.5.21 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: Apache-2.0 Imports: 12 Imported by: 5

README

reflectx

Golang reflect package hack tools

Go1.14 Go1.15 Go1.16

Field
  • reflectx.CanSet
  • reflectx.Field
  • reflectx.FieldByIndex
  • reflectx.FieldByName
  • reflectx.FieldByNameFunc
Named
  • reflectx.StructOf(fs)
  • reflectx.NamedTypeOf
  • reflectx.IsNamed
  • reflectx.ToNamed
Method
  • reflectx.Method

  • reflectx.MakeMethod

  • reflectx.NewMethodSet

  • reflectx.SetMethodSet

  • reflectx.StructToMethodSet

Interface
  • reflectx.InterfaceOf
  • reflectx.NamedInterfaceOf
  • reflectx.NewInterfaceType
  • reflectx.SetInterfaceType
SetElem
  • reflectx.SetElem

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EnableExportAllMethod = false
)
View Source
var (
	EnableStructOfExportAllField bool
)

Functions

func CanSet

func CanSet(v reflect.Value) reflect.Value

func Field

func Field(s reflect.Value, i int) reflect.Value

func FieldByIndex

func FieldByIndex(s reflect.Value, index []int) reflect.Value

func FieldByName

func FieldByName(s reflect.Value, name string) reflect.Value

func FieldByNameFunc

func FieldByNameFunc(s reflect.Value, match func(name string) bool) reflect.Value

func InterfaceOf added in v0.4.0

func InterfaceOf(embedded []reflect.Type, methods []reflect.Method) reflect.Type

func IsNamed added in v0.3.7

func IsNamed(typ reflect.Type) bool

func MakeEmptyInterface added in v0.4.0

func MakeEmptyInterface(pkgpath string, name string) reflect.Type

func MethodByIndex added in v0.4.0

func MethodByIndex(typ reflect.Type, index int) reflect.Method

func MethodByName added in v0.4.0

func MethodByName(typ reflect.Type, name string) (m reflect.Method, ok bool)

func NamedInterfaceOf added in v0.4.0

func NamedInterfaceOf(pkgpath string, name string, embedded []reflect.Type, methods []reflect.Method) reflect.Type

func NamedStructOf added in v0.3.2

func NamedStructOf(pkgpath string, name string, fields []reflect.StructField) reflect.Type

func NamedTypeOf added in v0.3.5

func NamedTypeOf(pkgpath string, name string, from reflect.Type) reflect.Type

func NewInterfaceType added in v0.5.3

func NewInterfaceType(pkgpath string, name string) reflect.Type

func NewMethodSet added in v0.5.3

func NewMethodSet(styp reflect.Type, maxmfunc, maxpfunc int) reflect.Type

NewMethodSet is pre define method set of styp maxmfunc - set methodset of T max member func maxpfunc - set methodset of *T + T max member func

func ReplaceType added in v0.5.5

func ReplaceType(pkg string, typ reflect.Type, m map[string]reflect.Type) (rtyp reflect.Type, changed bool)

func Reset added in v0.5.2

func Reset()

func SetElem added in v0.5.4

func SetElem(typ reflect.Type, elem reflect.Type)

func SetInterfaceType added in v0.5.3

func SetInterfaceType(typ reflect.Type, embedded []reflect.Type, methods []reflect.Method) error

func SetMethodSet added in v0.5.3

func SetMethodSet(styp reflect.Type, methods []Method, extractStructEmbed bool) error

func SetValue added in v0.3.5

func SetValue(v reflect.Value, x reflect.Value)

func StructOf

func StructOf(fields []reflect.StructField) reflect.Type

func StructToMethodSet added in v0.5.2

func StructToMethodSet(styp reflect.Type) reflect.Type

StructToMethodSet extract method form struct embed fields

func TypeLinks() []reflect.Type

func TypesByString added in v0.5.14

func TypesByString(s string) []reflect.Type

func UpdateField added in v0.5.2

func UpdateField(typ reflect.Type, rmap map[reflect.Type]reflect.Type) bool

Types

type ChanDir added in v0.3.5

type ChanDir int

ChanDir represents a channel type's direction.

const (
	RecvDir ChanDir             = 1 << iota // <-chan
	SendDir                                 // chan<-
	BothDir = RecvDir | SendDir             // chan
)

type Method added in v0.5.0

type Method struct {
	Name    string
	PkgPath string
	Pointer bool
	Type    reflect.Type
	Func    func([]reflect.Value) []reflect.Value
}

Method struct for MethodOf - name: method name - pointer: flag receiver struct or pointer - typ: method func type without receiver - fn: func with receiver as first argument

func MakeMethod added in v0.4.0

func MakeMethod(name string, pkgpath string, pointer bool, typ reflect.Type, fn func(args []reflect.Value) (result []reflect.Value)) Method

MakeMethod make reflect.Method for MethodOf - name: method name - pointer: flag receiver struct or pointer - typ: method func type without receiver - fn: func with receiver as first argument

type Named added in v0.3.7

type Named struct {
	Name    string
	PkgPath string
	Type    reflect.Type
	From    reflect.Type
	Kind    TypeKind
}

func ToNamed added in v0.3.7

func ToNamed(typ reflect.Type) (t *Named, ok bool)

type TypeKind added in v0.3.5

type TypeKind int
const (
	TkInvalid TypeKind = 1 << iota
	TkType
	TkMethod
)

type Value

type Value struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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