Documentation ¶
Overview ¶
Package reflecth provides helper functions for GoLang reflect package. It also includes binary, unary, shift and compare operations on reflect.Value as Go specification describes.
Index ¶
- func Assign(x reflect.Value, t reflect.Type) (r reflect.Value, ok bool)
- func AssignableTo(x reflect.Value, t reflect.Type) bool
- func BinaryOp(x reflect.Value, op token.Token, y reflect.Value) (r reflect.Value, err error)
- func ChanDirFromAst(dir ast.ChanDir) (r reflect.ChanDir)
- func ChanDirToAst(dir reflect.ChanDir) (r ast.ChanDir)
- func CompareOp(x reflect.Value, op token.Token, y reflect.Value) (r bool, err error)
- func Convert(x reflect.Value, t reflect.Type) (r reflect.Value, ok bool)
- func ConvertibleTo(x reflect.Value, t reflect.Type) bool
- func IsAnyInt(k reflect.Kind) bool
- func IsComplex(k reflect.Kind) bool
- func IsFloat(k reflect.Kind) bool
- func IsInt(k reflect.Kind) bool
- func IsUint(k reflect.Kind) bool
- func MakeSettable(x reflect.Value) reflect.Valuedeprecated
- func MustAssign(x reflect.Value, t reflect.Type) reflect.Value
- func MustConvert(x reflect.Value, t reflect.Type) reflect.Value
- func Set(dst, src reflect.Value)deprecated
- func ShiftOp(x reflect.Value, op token.Token, s uint) (r reflect.Value, err error)
- func TypeAssert(x reflect.Value, t reflect.Type) (r reflect.Value, ok bool, valid bool)
- func TypeBool() reflect.Type
- func TypeByte() reflect.Type
- func TypeComplex128() reflect.Type
- func TypeComplex64() reflect.Type
- func TypeEmptyInterface() reflect.Type
- func TypeFloat32() reflect.Type
- func TypeFloat64() reflect.Type
- func TypeInt() reflect.Type
- func TypeInt16() reflect.Type
- func TypeInt32() reflect.Type
- func TypeInt64() reflect.Type
- func TypeInt8() reflect.Type
- func TypeOfPtr(i interface{}) reflect.Type
- func TypeRune() reflect.Type
- func TypeString() reflect.Type
- func TypeUint() reflect.Type
- func TypeUint16() reflect.Type
- func TypeUint32() reflect.Type
- func TypeUint64() reflect.Type
- func TypeUint8() reflect.Type
- func TypeUintptr() reflect.Type
- func UnaryOp(op token.Token, y reflect.Value) (r reflect.Value, err error)
- func ValueOfPtr(i interface{}) reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignableTo ¶
AssignableTo is just a shortcut for x.Type().AssignableTo(t).
func BinaryOp ¶
BinaryOp performs binary operation <x><op><y> as Go language specification describes. Supported operations: && || + - * / % & | ^ &^ . If operation cannot be performed then error will be returned.
func ChanDirFromAst ¶
ChanDirFromAst preforms conversion channel direction from ast.ChanDir representation to reflect.ChanDir representation. ChanDirFromAst returns 0 if dir cannot be represented as reflect.ChanDir (if dir invalid itself).
func ChanDirToAst ¶
ChanDirToAst preforms conversion channel direction from reflect.ChanDir representation to ast.ChanDir representation. ChanDirToAst returns 0 if dir cannot be represented as ast.ChanDir (if dir invalid itself).
func CompareOp ¶
CompareOp performs compare operation <x><op><y> as Go language specification describes. Supported operations: < <= >= > == != . If operation cannot be performed then error will be returned.
func ConvertibleTo ¶
ConvertibleTo is just a shortcut for x.Type().ConvertibleTo(t).
func MakeSettable
deprecated
func MustAssign ¶
MustAssign assign x to newly created reflect.Value of type t. It panics if it is impossible to create reflect.Value of type t of if x cannot be assign to t.
func MustConvert ¶
MustConvert is just a x.Convert(t).
func Set
deprecated
Set assigns src to the value dst. It is similar to dst.Set(src) but this function also allow to set private fields. Primary reason for this is to avoid restriction with your own struct variable. It panics if CanAddr returns false. As in Go, x's value must be assignable to v's type.
Deprecated: In any case it is bad practice to change private fields in 3rd party variables/classes.
func ShiftOp ¶
ShiftOp performs shift operation <x><op><s> as Go language specification describes. Supported operations: << >> . If operation cannot be performed then error will be returned.
func TypeAssert ¶
TypeAssert perform GoLang type assertion (see language specs). Variable x must be of interface kind (or panic/undefined behaviour happened). Variable valid identify is assertion valid. Assertion is valid if t is of interface kind or if t implements type of x. In Go invalid assertion causes compile time error (something like "impossible type assertion: <t> does not implement <type of x>"). Variable ok identity is assertion true. Assertion is true if x is not nil and the value stored in x is of type t. Variable ok sets to false if valid is false, so it is valid way to check only variable ok and ignore variable valid if details of false result does not have mean.
func TypeEmptyInterface ¶
TypeEmptyInterface returns type of empty interface.
func TypeOfPtr ¶
TypeOfPtr returns type of value pointed to by i. If i is not a pointer than TypeOfPtr returns nil.
func UnaryOp ¶
UnaryOp performs unary operation <op><y> as Go language specification describes. Supported operations: + - ^ ! & <- . If operation cannot be performed then error will be returned. Special note for token.AND (&) operation: if passed y is not addressable (reflect.Value.CanAddr) then new variable will be created with the same as y type and value and address of new variable will be returned.
func ValueOfPtr ¶
ValueOfPtr returns value pointed to by i. If i is not a pointer than ValueOfPtr returns zero Value. This function is useful for passing interface to reflect.Value via passing pointer to interface to this function (it is impossible to make reflect.Value of kind interface via passing interface directly to ValueOf function).
Types ¶
This section is empty.